RoR - 未定义的方法`merge'

时间:2011-12-20 13:12:36

标签: ruby-on-rails ruby forms textfield

我正在用Thimothy Fisher的“RoR Bible”研究Ruby on Rails。但其中一个例子不起作用。这是代码 - http://pastebin.com/gtjLsdt0 错误是:NoMethodError Contact#new,第4行引出:

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

有什么问题?

1 个答案:

答案 0 :(得分: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版本!

相关问题