1
I am trying to create comment, through the form_for of 3 levels:
Article > Item > Comment
Controller:
def new
@comment = Comment.new
end
I have tried several ways, and they all fail. Look what I tried and the error that came back:
First attempt:
<%= form_for([@item, @item.comments.build]) do |f| %>
Error: Undefined method `item_comments_path' for
2nd Attempt:
<%= form_for ([@item, @comment]) do |f| %>
Error: First argument in form cannot contain nil or be Empty
Third attempt:
<%= form_for @category do |f| %>
<%= f.fields_for @item do |i| %>
<%= i.fields_for @comments do |c| %>
Error: Undefined method `model_name' for nil:Nilclass
I don’t know what else to try, how could I fix this?
I found the problem: I was inside the item show page, but rendering a partial add comment. I thought it would go through the Comment controller, but it was only going through the Item controller.
– Moisesello