【发布时间】:2011-04-25 19:14:12
【问题描述】:
我正在阅读 rails 3 的 railtutorial.org 在线书籍。
我已经完成了第 11 章的大部分内容,我们在其中添加了提交微博的功能。添加适当的代码后,我无法呈现页面。以下是返回的错误:
>
Pages#home 中的 NoMethodError
显示 c:/rails_projects/sample_app/app/views/shared/_error_messages.html.erb 其中第 >#1 行提出:
当你没想到时,你有一个 nil 对象! 您可能期望 ActiveRecord::Base 的实例。 评估 nil.errors 时发生错误 提取的源代码(第 1 行附近):
1:
<% if @user.errors.any? %>
2:<div id="error_explanation">
3:<h2><%= pluralize(@user.errors.count, "error") %>
4:prohibited this <%= object.class.to_s.underscore.humanize.downcase %>
模板包含的痕迹:app/views/shared/_micropost_form.html.erb, >app/views/pages/home.html.erb
如果我从 app\views\shared_micropost_form.html.erb 中删除以下行,页面将正确呈现 f.object %>
感谢任何帮助。
【问题讨论】:
-
你能显示 app\views\shared_micropost_form.html.erb 的代码吗
标签: ruby-on-rails ruby-on-rails-3