2011-12-20 74 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