【问题标题】:RoR - undefined method `merge'RoR - 未定义的方法“合并”
【发布时间】:2011-12-20 13:12:36
【问题描述】:

我正在使用 Thimothy Fisher 的“RoR Bible”来研究 Ruby on Rails。但是其中一个示例不起作用。这是代码 - http://pastebin.com/gtjLsdt0 错误是:NoMethodError in Contact#new where line #4 raise:

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

怎么了??

【问题讨论】:

    标签: ruby-on-rails ruby forms textfield


    【解决方案1】:

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

    不要这样写:

    <%= 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 版本!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-28
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多