Hi friends, I have two table.. 1) --------------------------------- users --------------------------------- id(pri) | user_name | email| ---------------------------------- 2) ----------------------------------------------- posts ----------------------------------------------- post_id | user_id(foreign_key)| title | body ------------------------------------------------- Relations is A user has many posts. I created a form for post. with title:----------------------------------- body:------------------------------------ ------------------------------------ ---------------------------------------- ----------------------------------------- submit_button. in controller I wrote logic for submit this form so that, all the title & body gets added into database. But, the foreign key is not being added. How am i suppose to do? -- Posted via ruby-forum.com.
On Aug 10, 10:27 am, Hunt Hunt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > in controller I wrote logic for submit this form so that, > all the title & body gets added into database. > > But, the foreign key is not being added. > > How am i suppose to do?Well in an ideal world you''ve have something containing the user that is creating the post (eg current_user) and you would have created your associations between these two classes. You could then do current_user.posts.create :title => ... Fred
Frederick Cheung wrote:> On Aug 10, 10:27�am, Hunt Hunt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> >> in controller I wrote logic for submit this form so that, >> all the title & body gets added into database. >> >> But, the foreign key is not being added. >> >> How am i suppose to do? > > Well in an ideal world you''ve have something containing the user that > is creating the post (eg current_user) and you would have created your > associations between these two classes. You could then do > current_user.posts.create :title => ... > > FredI think I need to use session for that. I am very new to Rails and web technology. can anybody refer me a good documentation on session in rails? and how can i avail it? -- Posted via ruby-forum.com.
On Aug 10, 12:26 pm, Hunt Hunt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Frederick Cheung wrote:> I think I need to use session for that. > I am very new to Rails and web technology. > can anybody refer me a good documentation on session in rails? > and how can i avail it?You could start by looking at the rails guide about action controller ( guides.rubyonrails.org/action_controller_overview.html#session ) There are a number of plugins/gems for handling authentication such as authlogic & restful_authentication Fred> -- > Posted viahttp://www.ruby-forum.com.