Rails 3.2 app:undefined 方法 'klass' for nil:NilClass 用于存在并在页面上呈现的类



我正在Dreamhost上运行一个非常直接的Rails 3.2应用程序(我知道它很蹩脚)。

错误为:

NoMethodError in Products#edit
Showing /home/emeraldcityguitars/emeraldcityguitars.com/releases/20120318040051/app/views/products/edit.html.erb where line #47 raised:
undefined method `klass' for nil:NilClass
Extracted source (around line #47):
44:   <div id="interior_sub_head"><h5 id="sub_green_head"><%= @product.title %></h5></div>
45:   <div id="interior_pad">
46: 
47:     <%= nested_form_for @product, :html => { :multipart => true } do |f| %>
48:     <%= f.error_messages %>
49: 
50:     <fieldset>  

听起来@product返回nil,但如果您查看第44行,在这种情况下请求@product时没有出错?

有什么想法吗?

编辑

完整产品#编辑视图:https://gist.github.com/2081340

+

_photo_fields.html视图:https://gist.github.com/5af2f88f29c21e24b42c

感谢

我遇到了同样的问题,我做了两次更改,不幸的是没有分别进行,其中一次或两次都解决了问题。

首先,在你的控制器中,你用编辑方法构建一张照片吗?

@product.photos.build if @product.photos.empty?

我在这篇博客文章的评论中发现了这一点。

其次,我在"link_to_dd"行中添加了嵌套类的符号,您已经有了这个符号。

我从has_many切换到has_one时也出现了同样的错误。阿佐洛的回应解决了我的问题。

删除了<%=f.link_to_dd……%>标记,一切都很顺利!

相关内容

最新更新