AdamSebWolf
2007-Feb-06 16:03 UTC
Submitting data from view to controller without using form objects or params?!
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Kim
2007-Feb-06 17:45 UTC
Re: Submitting data from view to controller without using form objects or params?!
It would help to see the relevant code. On Feb 6, 8:03 am, "AdamSebWolf" <adamsebw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Siggelkow
2007-Feb-06 18:19 UTC
Re: Submitting data from view to controller without using form objects or params?!
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 ... On Feb 6, 11:03 am, "AdamSebWolf" <adamsebw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---