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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 22, 10:07 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 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)You''ve writtten comments.create :id => params[:body] which I assume isn''t what you wanted. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> 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! :-) On 22 May, 10:16, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 22, 10:07 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > > > > > 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) > > You''ve writtten comments.create :id => params[:body] which I assume > isn''t what you wanted. > > Fred > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sat, May 22, 2010 at 5:23 AM, RubyonRails_newbie <craigwesty79-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:>> 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! :-) >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: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
i changed it to comment, and it returned this error: --- !map:HashWithIndifferentAccess any ideas? On 22 May, 10:23, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > 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! :-) > > On 22 May, 10:16, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > On May 22, 10:07 am, RubyonRails_newbie <craigwest...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > > wrote: > > > > 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) > > > You''ve writtten comments.create :id => params[:body] which I assume > > isn''t what you wanted. > > > Fred > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.