我正在使用rails 2.3.5。我有一個博客模型,博客有很多評論。這是我的博客控制器顯示操作爲嵌套對象創建隱藏字段時出錯
def show
@blog = Blog.find(params[:id])
@comment = Comment.new
end
我會顯示博客,最後會有一個創建評論的選項。所以我在blog/show.html.erb中加入了這個。
<% form_remote_for @comment do |f| %>
<%= f.label :content %>
<%= f.text_area :content, :rows => 6 %>
<%= f.hidden_field :blog => @blog %>
<%= f.submit %>
<% end %>
,但我得到以下錯誤,當我運行在博客#顯示
這 NoMethodError顯示應用程序/視圖/博客/ show.html.erb其中線#270提出:
undefined method `blog#<Blog:0xb677d8d0>' for #<Comment:0xb67762b0>
提取的源(圍繞線#270):
在這種情況下,我的<%form_remote_for指向什麼? – Rahul
'@comment'僅限'@comment = @ blog.comments.build' –