RoR - 未定义的方法“合并”;

发布于 2024-12-22 00:02:16 字数 636 浏览 1 评论 0原文

我正在通过 Thimothy Fisher 的《RoR Bible》学习 Ruby on Rails。但其中一个例子不起作用。它的代码 - http://pastebin.com/gtjLsdt0 错误为:Contact#new 中的 NoMethodError,其中第 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

出了什么问题?

I'm studing Ruby on Rails with the "RoR Bible" by Thimothy Fisher. But one of the examples doesn't work. It's code - http://pastebin.com/gtjLsdt0
The error is: NoMethodError in Contact#new where line #4 raised:

undefined method `merge' for "first_name":String

that's my contact_controller. I'm just retyping example's code, and there weren't any words about merge

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

What is wrong??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁拥 2024-12-29 00:02:16

哈哈,这个例子是完全错误的!

不要这样写:

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

您应该写

<%= f.text_field :first_name %>

因为通过使用 f.field_type 您将字段分配给提供 f:contact 表单迭代方法!您也可以编写

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

而不是编写手册!

// 我查了一下你提到的书,它似乎已经过时了。你可以购买“The Rails 3 Way”或其他东西。可以支持当前的 Rails 版本!

Lol that example is completely wrong!

Instead of writing sth like this:

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

You should write

<%= f.text_field :first_name %>

Because by using f.field_type you assign the field to the :contact form which provides the f methods by iteration! Also you can write

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

Instead of writing it manual!

// I loked up the book you refered it seems to be quit outdated. You may buy "The Rails 3 Way" or sth. that can hold up to the current rails version!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文