Query

Hi friends,

I have two table…


       users

id(pri) | user_name | email|


      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?

On Aug 10, 10:27 am, Hunt H. [email protected]
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 C. wrote:

On Aug 10, 10:27�am, Hunt H. [email protected]
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

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?

On Aug 10, 12:26 pm, Hunt H. [email protected]
wrote:

Frederick C. 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
( http://guides.rubyonrails.org/action_controller_overview.html#session
)
There are a number of plugins/gems for handling authentication such as
authlogic & restful_authentication

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs