Forum: Ruby on Rails Submitting data from view to controller without using form o

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Be76443ea33cd2c4fe8f43e7441fc7fe?d=identicon&s=25 AdamSebWolf (Guest)
on 2007-02-06 17:04
(Received via mailing list)
Hi Guys,
My first post (and second RoR app ever!) so expect an easy problem,

I've been making a blog (suprise suprise, my first app was a webstore
too!), and I've got a charming front page, listing my posts with some
nice css and a really clean interface. Beneath each post I have a
comments form, with a name field, a textarea for the body, and a
submit post button. Easy!
The form's action is set to call the 'add_comment' action in my
controller, and the input fields are set to correspond to
and comment.body in the Comment object. This all works perfectly! I
pull out the comment object from params with params[:comment] and toss
it into the database with, only to see exceptions that I
haven't told the comment which post it belongs to! (post_id is not
null, see below)
In the comments table in my database, there are: id, post_id, name,
body. post_id is linked to the posts table by id, and I've done all
the work to set this up correctly.

My question is:
Does the Comment object have a post_id property from the table?
If so, how do I set it from within my blog.rhtml page? I currently
have a "for post in @posts" loop, and so post corresponds to the
relavent post_id. Bear in mind that I'm using multiple duplicate
If not, how do I set the post_id property?

Thanks a lot, I'm sure this is a really obvious one I've totally
Sebastian Wolf
8e73782b5a220c5d923a0195667e7406?d=identicon&s=25 Kim (Guest)
on 2007-02-06 18:46
(Received via mailing list)
It would help to see the relevant code.
456f5e099eb136439d751598e32d8607?d=identicon&s=25 Bill Siggelkow (Guest)
on 2007-02-06 19:20
(Received via mailing list)
Yes, there will be a 'post_id' property on your comment ... one way
would be to set a hidden field on your form holding the post id. There
are about 10 other ways of doing this ...
This topic is locked and can not be replied to.