# :body is not being stored in the database

**URL:** <https://www.ruby-forum.com/t/body-is-not-being-stored-in-the-database/189028>\
**Category:** Rails\
**Created:** [May 22, 2010, 11:08am UTC](https://www.ruby-forum.com/t/body-is-not-being-stored-in-the-database/189028 "2010-05-22T11:08:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [May 22, 2010, 11:08am UTC](https://www.ruby-forum.com/t/body-is-not-being-stored-in-the-database/189028/1 "2010-05-22T11:08:18Z")

</div>

Hello there,

I have a blog that people can leave comments on.

I have used the following code to attempt to save the comment value to  
the database:

def comment

```
@user = User.find(session[:user_id])

 Blogpost.find(params[:id]).comments.create(:id =>

```

params[:body], :user\_id =\> session[:user\_id])  
flash[:notice] = “Added your comment”  
redirect\_to :action =\> “show”, :id =\> params[:id]  
end

the values in the database are:  
id  
body  
blogpost\_id  
user\_id

ALl these values EXCEPT the body get populated.

Using my code above, can anyone see why the body isn’t being stored?  
(it just gets set as NULL)

Hope someone can help…  
Thanks,

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [May 22, 2010, 11:18am UTC](https://www.ruby-forum.com/t/body-is-not-being-stored-in-the-database/189028/2 "2010-05-22T11:18:15Z")

</div>

On May 22, 10:07 am, RubyonRails\_newbie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> (it just gets set as NULL)  
> You’ve writtten comments.create :id =\> params[:body] which I assume  
> isn’t what you wanted.

Fred

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [May 22, 2010, 11:25am UTC](https://www.ruby-forum.com/t/body-is-not-being-stored-in-the-database/189028/3 "2010-05-22T11:25:17Z")

</div>

> You’ve writtten comments.create :id =\> params[:body] which I assume  
> isn’t what you wanted.

Well- i’d started to follow a tutorial, but didn’t quite understand  
it.  
ANy idea what id should be to allow it to save?

I’ve tried many combinations of the id, :user\_id, body etc and when I  
change it, the null value shifts to the user\_id, or the blogpost\_id.

I’m probably missing something really simple, but i was looking at  
this all last night! 🙂

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [May 22, 2010, 12:39pm UTC](https://www.ruby-forum.com/t/body-is-not-being-stored-in-the-database/189028/4 "2010-05-22T12:39:38Z")

</div>

i changed it to comment, and it returned this error:  
— !map:HashWithIndifferentAccess

any ideas?

On 22 May, 10:23, RubyonRails\_newbie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [May 22, 2010, 12:43pm UTC](https://www.ruby-forum.com/t/body-is-not-being-stored-in-the-database/189028/5 "2010-05-22T12:43:43Z")

</div>

On Sat, May 22, 2010 at 5:23 AM, RubyonRails\_newbie  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m probably missing something really simple, but i was looking at  
> this all last night! 🙂

The id gets assigned automatically when a new record is saved, and  
create saves the record.

def comment

@user = User.find(session[:user\_id])

```
Blogpost.find(params[:id]).comments.create(:body =>

```

params[:body], :user =\> @user)  
…

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Github: [rubyredrick (Rick DeNatale) · GitHub](http://github.com/rubyredrick)  
Twitter: @RickDeNatale  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)
