# Adding data from the model

**URL:** <https://www.ruby-forum.com/t/adding-data-from-the-model/145013>\
**Category:** Rails\
**Created:** [August 5, 2008, 7:31am UTC](https://www.ruby-forum.com/t/adding-data-from-the-model/145013 "2008-08-05T07:31:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 5, 2008, 7:31am UTC](https://www.ruby-forum.com/t/adding-data-from-the-model/145013/1 "2008-08-05T07:31:11Z")

</div>

Hi, I have a form that I need to add default data when is passed into  
the DB…  
for example I have a create post, were the user can add tittle, text  
etc…  
but I need to add who created so is on record etc  
I will like to know how will I do this from the model, since I think  
that is the right place to do this…  
on php I will just add hiden fields to the form and pass the variables  
but there should be a nice way in rails…

thanks

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 5, 2008, 7:49am UTC](https://www.ruby-forum.com/t/adding-data-from-the-model/145013/2 "2008-08-05T07:49:54Z")

</div>

On Tue, Aug 5, 2008 at 12:30 AM, rek2 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi, I have a form that I need to add default data when is passed into  
> the DB…  
> for example I have a create post, were the user can add tittle, text etc…  
> but I need to add who created so is on record etc  
> I will like to know how will I do this from the model, since I think  
> that is the right place to do this…  
> on php I will just add hiden fields to the form and pass the variables  
> but there should be a nice way in rails…

Post.create( params[:post].merge( :user\_id =\> session[:user\_id] ) )

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
