can anybody tell me why my controller is not creating a new comment,
but my view lists comments that i manually add to the database?
here is my view code:
<% for comment in @post.post_comments %>
<%= comment.body %>
<%= comment.email_address %>
<% end %>
<%= form_tag :action => "comment", :id => @post %>
<%= text_area "post_comment", "body" %><br/>
<%= submit_tag "Comment!" %>
and here is my controller code:
flash[:notice] = "Added your comment."
redirect_to :action => "show", :id => params[:id]
i have models called post and post_comment and tables called posts and
i don't get any error messages and it redirects back to the appropriate
post on the show page, but the flash doesn't work and the comment isn't
your problem lies with Instance versus Class methods.
Post.find returns an array of post instances. The instance method post_comments returns an array of comments instances.
The create method doesn't belong either to a particular comment instance, nor to Array.
You should be calling Post.create and adjusting your params as such.
Plus if you check your development.log, you'll likely see something like "create is not a method of Array". This log should be a key source of debugging.