Reputation: 73
How can i have a comments form above the comments themselves.
Works
@post = Post.find(params[:id])
@post.comments.each do |comment|
comment.id
end
@post.comments.build
# form here
end
Desired but fails
@post = Post.find(params[:id])
@post.comments.build
# form here
end
@post.comments.each do |comment|
comment.id
end
Upvotes: 0
Views: 98
Reputation: 4877
controller
@post = Post.find(params[:id])
@comment = @post.comment.new
view
form_for @comment do |f|
...
end
@post.comments.each do |comment|
comment.id
end
Upvotes: 1