I am trying to create a comment that could comment on other comments but are all derived from a single post.
What is especially troubling for me is trying to figure out how to make it so that this can all be achieved in the post show and not its edit or new. Is this archtecturally reasonable?
That way I can access it via Post.comments
, or Comment.comments
etc. or Comments.parent
My Models:
#comment.rb
belongs_to :post
belongs_to :parent, :class_name => 'Comment'
has_many :children, :class_name => 'Comment'
validates_presence_of :text
#post.rb
has_many :comments
accepts_nested_attributes_for :comments
posts_controller
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post }
end
end
routes.rb
resource :comments
I made my comment table have a :text
and :post_id
attribute. Though I don't think it needs a :post_id
,
What should my form look like, where should it be?
Here's my awful attempt :
- form_for @post do |f|
- f.fields_for :comments do |c|
= f.label 'Comments'
= f.text_area :text
= f.submit 'Submit'
But it seems unecessary to do that.