2011-12-20 29 views
0

我正在用Thimothy Fisher的“RoR Bible”来研究Ruby on Rails。但其中一个例子不起作用。它的代码 - http://pastebin.com/gtjLsdt0 的错误是:NoMethodErrorContact#new其中4号线提出:RoR - 未定义的方法`合并'

undefined method `merge' for "first_name":String 


这是我的contact_controller。我只是重新输入例子的代码,有没有关于合并

class ContactController < ApplicationController 
    def index 
    @contacts = Contact.find(:all); 
    end 

    def show 
    end 

    def new 
    @contact = Contact.new; 
    end 

    def create 
    end 

    def update 
    end 

end 

什么错什么话?

回答

4

大声笑这个例子是完全错误的!

而是写某事像这样的:

<%= f.text_field 'contact', 'first_name' %> 

你应该写

<%= f.text_field :first_name %> 

由于使用f.field_type您现场分配给:contact形式通过迭代提供f方法!你也可以写

<%= f.label :first_name, "description of first_name" %> 

而不是写它手动!

//我把你提到的那本书放了下来,似乎已经过时了。你可能会购买“The Rails 3 Way”或者某物。可以支持当前的rails版本!

+0

查看更新.... – davidb 2011-12-20 13:45:21

相关问题