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| %> Now, this is what I know: form_for: used to generate a form. @post: the object form_for is bound to. The part I didn''t get here is: @post.comments.build What does that part provide me with? 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 Aug 14, 2:23 pm, Abder-Rahman Ali <li...-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| %> > > Now, this is what I know: > > form_for: used to generate a form. > @post: the object form_for is bound to. > > The part I didn''t get here is: > > @post.comments.build > > What does that part provide me with?It''s a namespaced resource - it''s a form for a new comment belonging to @post Fred> > Thanks. > -- > 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:> On Aug 14, 2:23�pm, Abder-Rahman Ali <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> form_for: used to generate a form. >> @post: the object form_for is bound to. >> >> The part I didn''t get here is: >> >> @post.comments.build >> >> What does that part provide me with? > > It''s a namespaced resource - it''s a form for a new comment belonging > to @post > > FredThanks Fred. What is "namespaced resource"? 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 14 August 2010 15:34, Abder-Rahman Ali <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote: >> On Aug 14, 2:23�pm, Abder-Rahman Ali <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> form_for: used to generate a form. >>> @post: the object form_for is bound to. >>> >>> The part I didn''t get here is: >>> >>> @post.comments.build >>> >>> What does that part provide me with? >> >> It''s a namespaced resource - it''s a form for a new comment belonging >> to @post >> >> Fred > > Thanks Fred. > > What is "namespaced resource"?Have a look at the guide on routing, (at http://edgeguides.rubyonrails.org/) it explains the use of namespaces. Also google would have given you useful information here again. Colin -- 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.
Thanks Colin. -- 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.
This is a method generated for you by rails as a result of the
associtions declared in the Post and Comment models - in this case
belongs_to and has_many. Comments belongs to a post, and a post can
have many comments.
Rails creates quite a number of theses methods in response to the
association, and different associations (has_one,
has_and_belongs_to_many etc.) create different sets of methods - more
details in the API docs:
http://edgeapi.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
collection.build is one of these methods, and the API docs explain it
pretty well:
"collection.build(attributes = {}, …) Returns one or more new
objects of the collection type that have been instantiated with
attributes and linked to this object through a foreign key, but have
not yet been saved."
"collection" in this case is @post.comments
(None of of which has anything to do with namespaced resources...)
Matt.
On Aug 14, 2:23 pm, Abder-Rahman Ali
<li...-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| %>
>
> Now, this is what I know:
>
> form_for: used to generate a form.
> @post: the object form_for is bound to.
>
> The part I didn''t get here is:
>
> @post.comments.build
>
> What does that part provide me with?
>
> Thanks.
> --
> 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.