Let''s say I have a simple RESTful scaffold named: product and the new and edit forms contain something like: <% form_for( @product ) do |f| %> <%= f.text_field :name %> <% end %> Everything is cool and working. Now, let''s say I want to use a belongs_to in product.rb class Product belongs_to :some_other_model, blah, blah... end Is it possible to do something on the product form to reference some_other_model and capture form field values?? I''m thinking something along the lines of: <% form_for( @product ) do |f| %> <%= f.text_field :some_other_model.other_name %> <% end %> or whatever the syntax would be... 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thatcher.craig-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-29 02:48 UTC
Re: form_for and belongs_to
you would wrap these in a fields_for block. ie <% form_for( @product ) do |f| %> <%= f.text_field :some_other_model.other_name %> <fieldset> <% fields_for :some_other_model do |o| %> <%= o.text_field o.other_name %> <% end %> </fieldset> <% end %> On Jan 28, 7:08 pm, "rails.impaired" <resident.mo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Let''s say I have a simple RESTful scaffold named: product > > and the new and edit forms contain something like: > > <% form_for( @product ) do |f| %> > > <%= f.text_field :name %> > > <% end %> > > Everything is cool and working. Now, let''s say I want to use a > belongs_to in product.rb > > class Product > > belongs_to :some_other_model, blah, blah... > > end > > Is it possible to do something on the product form to reference > some_other_model and capture form field values?? > > I''m thinking something along the lines of: > > <% form_for( @product ) do |f| %> > > <%= f.text_field :some_other_model.other_name %> > > <% end %> > > or whatever the syntax would be... > > 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---