Hi, I am totally stuck with a problem creating an object. This is the request: Started POST "/posts/31/comments" for 127.0.0.1 at 2011-07-31 21:11:01 +0200 Processing by CommentsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"cU60iQ+GXqB8fVREw8mOMgkmvaLIQZa+6puTFqxmV5s=", "comment"=>{"email"=>"", "website"=>"", "comment"=>""}, "commit"=>"Create Comment", "post_id"=>"31"} So I think I would get the object with the following code within the create action of the CommentsController. def create @comment = Comment.new(params[:comment]) end But an inspect on @comment shows me that the object is empty: #<Comment id: nil, comment: "", email: "", website: "", post_id: nil, created_at: nil, updated_at: nil> May anyone give me a hint what i am doing wrong? I appreciate your help. Thanks. Kind regards, Jan -- 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 Sun, Jul 31, 2011 at 12:29 PM, Jan Marquardt <janno-R+7h4gkPAorrZ44/DZwexQ@public.gmane.org> wrote:> Started POST "/posts/31/comments" for 127.0.0.1 at 2011-07-31 21:11:01 +0200 > Processing by CommentsController#create as HTML > Parameters: {"utf8"=>"✓", > "authenticity_token"=>"cU60iQ+GXqB8fVREw8mOMgkmvaLIQZa+6puTFqxmV5s=", > "comment"=>{"email"=>"", "website"=>"", "comment"=>""}, "commit"=>"Create > Comment", "post_id"=>"31"} > > So I think I would get the object with the following code within the create > action of the CommentsController. > > def create > @comment = Comment.new(params[:comment]) > end > > But an inspect on @comment shows me that the object is empty: > > #<Comment id: nil, comment: "", email: "", website: "", post_id: nil, > created_at: nil, updated_at: nil> > > May anyone give me a hint what i am doing wrong?What are you expecting? Your request has a punch of empty comment parameters; the only actual value is "post_id" which you''re ignoring. If "post_id" is an attribute of comment, why isn''t it part of the comments parameters? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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.
Am 31.07.11 22:02, schrieb Hassan Schroeder:> On Sun, Jul 31, 2011 at 12:29 PM, Jan Marquardt<janno-R+7h4gkPAorrZ44/DZwexQ@public.gmane.org> wrote: > >> Started POST "/posts/31/comments" for 127.0.0.1 at 2011-07-31 21:11:01 +0200 >> Processing by CommentsController#create as HTML >> Parameters: {"utf8"=>"✓", >> "authenticity_token"=>"cU60iQ+GXqB8fVREw8mOMgkmvaLIQZa+6puTFqxmV5s=", >> "comment"=>{"email"=>"", "website"=>"", "comment"=>""}, "commit"=>"Create >> Comment", "post_id"=>"31"} >> >> So I think I would get the object with the following code within the create >> action of the CommentsController. >> >> def create >> @comment = Comment.new(params[:comment]) >> end >> >> But an inspect on @comment shows me that the object is empty: >> >> #<Comment id: nil, comment: "", email: "", website: "", post_id: nil, >> created_at: nil, updated_at: nil> >> >> May anyone give me a hint what i am doing wrong? > > What are you expecting? Your request has a punch of empty comment > parameters; the only actual value is "post_id" which you''re ignoring. > > If "post_id" is an attribute of comment, why isn''t it part of the comments > parameters? >Thanks Hassan, this was the epiphany i needed. I didn''t realized that post_id isn''t within the comment hash. Sorry for bothering you with this stupid question. Kind regards, Jan -- 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.