Hello,
I’m a newbie to rails, ruby, and web development in general, and I’m
having trouble with belongs_to and has_xxx relationships.
For example, right now I’m trying to get the 15 minute blog which is
listed on the page to work, and when I try to post a comment, I’m
getting this message:
“Couldn’t find Post without an ID”
Also, when I try and scaffold the comments attribute, post_id does not
show up on the list. However, it seems to be there when I look at the
schema file:
create_table “comments”, :force => true do |t|
t.column “body”, :text
t.column “post_id”, :integer
end
I’m thinking the post_id attribute not showing up as a parameter when I
run the scaffold and the “Couldn’t find Post without an ID” is related.
This is the code in the controller:
def comment
Blogitem.find(params[:id]).comments.create(params[:comment])
flash[:notice] = “Added your comment”
redirect_to :action => “show”, :id => params[:id]
end
And this is the code that I’m trying to run:
<%= form_tag :action => “comment”, :id => @post %>
<%= text_area “Comment”, “body” %>
<%= submit_tag “Comment!” %>
Very concrete help is really appreciated, since I’m quite new at both
rails and ruby. Also, does anyone know where I can find the source code
to the 15 minute blog? I keep checking and double checking my
code/databases/etc. against what’s in the video but I’m not seeing the
problem. Thank you very much!