At the following: http://edgeguides.rubyonrails.org/getting_started.html Under: 7.4 Generating a Controller It mentions the following: <%= form_for([@post, @post.comments.build]) do |f| %> Why should we insert TWO arguments? Doesn''t @post.comments.build do the idea? Since I need a form for the comments belonging to @post? What is the use of the FIRST @post? It seems that we are passing an array here? Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sun, Aug 15, 2010 at 8:28 AM, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> At the following: http://edgeguides.rubyonrails.org/getting_started.html > > Under: 7.4 Generating a Controller > > It mentions the following: > > <%= form_for([@post, @post.comments.build]) do |f| %> > > Why should we insert TWO arguments? > > Doesn''t @post.comments.build do the idea? Since I need a form for the > comments belonging to @post? > > What is the use of the FIRST @post?It''s because comment is setup as a resource nested within post. The form_for needs to generate the right combination of url and http verb, and this depends on whether or not the comment is a new record. The form_for helper is designed to allow the same form to be used both for the new and edit views. Passing an array tells form_for that it''s a nested resource. In this case, @post.comments.build will be a new record, it won''t have an id until it''s saved. Let''s say that the id of @post is 42. Then the form should be set up to send a post request using the uri path ''posts/42/comments If it was the edit case then the comment would have an id, say 432, and you''d use something like form_for @post, @comment where the edit action in the controller set both instance variables, and the form would send a put request to the url ''post/42/comments/432'' If you just gave form_for the single value @post.comments.build then it assumes that the comment resources isn''t nested and it would post to the uri path ''comments'' but the way the routes are specified this isn''t going to work. Does that make sense? -- 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.
Thanks s lot Rick for this nice explnation. Yes, does make sense. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rick, Just a small note under "links" at your blog, it seems tht the "Redhanded" is broken. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rick, Seems this is broken also at your LinkedIn: http://speakerrate.com/speaker/395-rdenatale This is beside "Websites". -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.