:body is not being stored in the database

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,

On May 22, 10:07 am, RubyonRails_newbie [email protected]
wrote:

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

Fred

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! :slight_smile:

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

any ideas?

On 22 May, 10:23, RubyonRails_newbie [email protected]

On Sat, May 22, 2010 at 5:23 AM, RubyonRails_newbie
[email protected] wrote:

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

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/
Github: rubyredrick (Rick DeNatale) · GitHub
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale