0

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
André Medeiros
  • 810
  • 4
  • 13

1 Answers1

1

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
TomDunning
  • 4,829
  • 1
  • 26
  • 33