# Query

**URL:** <https://www.ruby-forum.com/t/query/173482>\
**Category:** Rails\
**Created:** [August 10, 2009, 11:27am UTC](https://www.ruby-forum.com/t/query/173482 "2009-08-10T11:27:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/71e660/32.png) [@hunt](https://www.ruby-forum.com/u/hunt)\
**Post date:** [August 10, 2009, 11:27am UTC](https://www.ruby-forum.com/t/query/173482/1 "2009-08-10T11:27:21Z")

</div>

Hi friends,

I have two table…

1. 

* * *

```
       users

```

* * *

## id(pri) | user\_name | email|

1. 

* * *

```
      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?

---

<div class="post-metadata">

**Author:** ![hunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/71e660/32.png) [@hunt](https://www.ruby-forum.com/u/hunt)\
**Post date:** [August 10, 2009, 11:47am UTC](https://www.ruby-forum.com/t/query/173482/2 "2009-08-10T11:47:39Z")

</div>

On Aug 10, 10:27 am, Hunt H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![hunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/71e660/32.png) [@hunt](https://www.ruby-forum.com/u/hunt)\
**Post date:** [August 10, 2009, 1:26pm UTC](https://www.ruby-forum.com/t/query/173482/3 "2009-08-10T13:26:30Z")

</div>

Frederick C. wrote:

> On Aug 10, 10:27ï¿½am, Hunt H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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?

---

<div class="post-metadata">

**Author:** ![hunt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/71e660/32.png) [@hunt](https://www.ruby-forum.com/u/hunt)\
**Post date:** [August 10, 2009, 1:55pm UTC](https://www.ruby-forum.com/t/query/173482/4 "2009-08-10T13:55:49Z")

</div>

On Aug 10, 12:26 pm, Hunt H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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  
( [Action Controller Overview — Ruby on Rails Guides](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
