# Submitting data from view to controller without using form o

**URL:** <https://www.ruby-forum.com/t/submitting-data-from-view-to-controller-without-using-form-o/84632>\
**Category:** Rails\
**Created:** [February 6, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/submitting-data-from-view-to-controller-without-using-form-o/84632 "2007-02-06T17:04:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdamSebWolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@AdamSebWolf](https://www.ruby-forum.com/u/AdamSebWolf)\
**Post date:** [February 6, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/submitting-data-from-view-to-controller-without-using-form-o/84632/1 "2007-02-06T17:04:36Z")

</div>

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 comment.name  
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 comment.save, 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  
forms.  
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  
missed,  
Sebastian Wolf

---

<div class="post-metadata">

**Author:** ![AdamSebWolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@AdamSebWolf](https://www.ruby-forum.com/u/AdamSebWolf)\
**Post date:** [February 6, 2007, 6:46pm UTC](https://www.ruby-forum.com/t/submitting-data-from-view-to-controller-without-using-form-o/84632/2 "2007-02-06T18:46:48Z")

</div>

It would help to see the relevant code.

---

<div class="post-metadata">

**Author:** ![AdamSebWolf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f1d935/32.png) [@AdamSebWolf](https://www.ruby-forum.com/u/AdamSebWolf)\
**Post date:** [February 6, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/submitting-data-from-view-to-controller-without-using-form-o/84632/3 "2007-02-06T19:20:53Z")

</div>

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 …
