<% @user.comments.each_with_index do |comment,index| %> ................ ................ <%= form_for [Comment, Subcomment.new],:remote => true do |form| %> <div id="body"> <%= form.text_field :body %> </div> <% form.hidden_field :comment_id ,index[1] %> <p> <%= form.submit %> </p> <% end %> <% end %> It insists that comment_id = Comment Started POST "/comments/Comment/subcomments" for 127.0.0.1 at 2011-07-17 17:31:54 +0100 Processing by SubcommentsController#create as JS Parameters: {"utf8"=>"✓", "authenticity_token"=>"Ca9IHcB/No8OJ/9MLtXSeuas7n1Mp8GyxpIAMLJxMXo=", "subcomment"=>{"body"=>"cat"}, "commit"=>"Create Subcomment", "comment_id"=>"Comment"} What is the correct way to do this? -- Posted via http://www.ruby-forum.com/. -- 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 Jul 17, 5:45 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> <% @user.comments.each_with_index do |comment,index| %> > ................ > ................ > > <%= form_for [Comment, Subcomment.new],:remote => true do |form| > %>Here you should put the comment the subcomment is for, not Comment. If you do that then you shouldn''t need a hidden_field with the comment_id. Fred> <div id="body"> > <%= form.text_field :body %> > </div> > <% form.hidden_field :comment_id ,index[1] %> > <p> > <%= form.submit %> > </p> > <% end %> > <% end %> > > It insists that comment_id = Comment > > Started POST "/comments/Comment/subcomments" for 127.0.0.1 at 2011-07-17 > 17:31:54 +0100 > Processing by SubcommentsController#create as JS > Parameters: {"utf8"=>"✓", > "authenticity_token"=>"Ca9IHcB/No8OJ/9MLtXSeuas7n1Mp8GyxpIAMLJxMXo=", > "subcomment"=>{"body"=>"cat"}, "commit"=>"Create Subcomment", > "comment_id"=>"Comment"} > > What is the correct way to do this? > > -- > Posted viahttp://www.ruby-forum.com/.-- 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.
Frederick Cheung wrote in post #1011256:>> >> <%= form_for [Comment, Subcomment.new],:remote => true do |form| >> %> > > Here you should put the comment the subcomment is for, not Comment. If > you do that then you shouldn''t need a hidden_field with the > comment_id. > > FredIf I do that I get this in the terminal. Started POST "/comments/2/subcomments" for 127.0.0.1 at 2011-07-17 19:00:55 +0100 Processing by SubcommentsController#create as JS Parameters: {"utf8"=>"✓", "authenticity_token"=>"Ca9IHcB/No8OJ/9MLtXSeuas7n1Mp8GyxpIAMLJxMXo=", "subcomment"=>{"body"=>"dog"}, "commit"=>"Create Subcomment", "comment_id"=>"2"} User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 4 LIMIT 1 AREL (0.3ms) INSERT INTO "subcomments" ("body", "commenter", "comment_id", "created_at", "updated_at") VALUES (''dog'', ''natty'', NULL, ''2011-07-17 18:00:56.130372'', ''2011-07-17 18:00:56.130372'') Rendered comments/_subcomment.html.erb (0.5ms) Rendered subcomments/create.js.erb (4.1ms) Completed 200 OK in 300ms (Views: 16.8ms | ActiveRecord: 0.9ms) Why won''t it pass the comment_id when saving? Neil -- Posted via http://www.ruby-forum.com/. -- 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.
Neil Bye wrote in post #1011261:> Frederick Cheung wrote in post #1011256: > >>> >>> <%= form_for [Comment, Subcomment.new],:remote => true do |form| >>> %> >> >> Here you should put the comment the subcomment is for, not Comment. If >> you do that then you shouldn''t need a hidden_field with the >> comment_id. >> >> Fred >Strike last posting , there was an error in the controller. All OK now. Still don''t know why I got the error in my first post.> Neil-- Posted via http://www.ruby-forum.com/. -- 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 Jul 17, 7:32 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Neil Bye wrote in post #1011261: > > > Frederick Cheung wrote in post #1011256: > > >>> <%= form_for [Comment, Subcomment.new],:remote => true do |form| > >>> %> > > >> Here you should put the comment the subcomment is for, not Comment. If > >> you do that then you shouldn''t need a hidden_field with the > >> comment_id. > > >> Fred > > Strike last posting , there was an error in the controller. All OK now. > Still don''t know why I got the error in my first post. >Because your routes are setup to pull comment_id from the URL. Fred> > Neil > > -- > Posted viahttp://www.ruby-forum.com/.-- 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.