user1283644
user1283644

Reputation: 73

Comments form above comments

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

Answers (1)

TomDunning
TomDunning

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

Related Questions