: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,

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:

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)
   ...

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

any ideas?