Hi all, I am sure that this is documented somewhere, but I can''t find it. I have a class A that has references class B. Like, a.b.name. I was wondering how to represent that with form_for? <% form_for(@a) do |f| %> <%= f.text_field "b.name" %> <% end %> That doesn''t work, but it kinda shows you what I am talking about. Any help at all would be appreciated. Thanks! -fREW --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
So I''m assuming each instance of class A only references one instance of class B. If not, this answer changes, but if that''s the case just let me know. In the model A.rb: belongs_to :b In the model B.rb: has_many :as # or belongs_to :a if the relationship is one-to-one In the migration for A: t.integer :b_id Then everything should be kosher. ESPNDev On May 20, 3:03 pm, "fri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <fri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I am sure that this is documented somewhere, but I can''t find it. I > have a class A that has references class B. Like, a.b.name. I was > wondering how to represent that with form_for? > > <% form_for(@a) do |f| %> > <%= f.text_field "b.name" %> > <% end %> > > That doesn''t work, but it kinda shows you what I am talking about. > > Any help at all would be appreciated. Thanks! > > -fREW--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> In the model A.rb: > belongs_to :b > > In the model B.rb: > has_many :as # or belongs_to :a if the relationship is one-to-one > > In the migration for A: > t.integer :b_idWell, that''s all correct. But I already have the model and migrations defined. I just want to know how to set up a form with form_for to set values for a.b.blah. -fREW --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Oh my bad. You need to use <%= text_field_tag "b", @a.b.name %> And then you''ll be able to access stuff with params[:b] On May 20, 3:33 pm, "fri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <fri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > In the model A.rb: > > belongs_to :b > > > In the model B.rb: > > has_many :as # or belongs_to :a if the relationship is one-to-one > > > In the migration for A: > > t.integer :b_id > > Well, that''s all correct. But I already have the model and migrations > defined. I just want to know how to set up a form with form_for to > set values for a.b.blah. > > -fREW--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Oh my bad. You need to use > > <%= text_field_tag "b", @a.b.name %> > > And then you''ll be able to access stuff with params[:b]Excellent! This should get me going. Is there any way that I can have the tag formatted the way it is with the rest of the object? For example, in general if my class is Monster with various params I''d have monster[height], monster[weight], etc with id''s being moster_height, monster_weight And then of course this makes it really easy for me to just do @monster.update_attributes(params[:monster]) Is there a way that I could have the tags for this set to be along those same lines, as follows: monster[pet][type], monster[pet][name] with monster_pet_type, monster_pet_name Either way, thanks a lot for the help! -fREW --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
wtf? Whatever happened to using fields_for? fields_for @a.b do |b| b.text_field "name" end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On May 20, 6:35 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> wtf? > > Whatever happened to using fields_for? > > fields_for @a.b do |b| > b.text_field "name" > endWell, that works really well, but what if I want that INSIDE of the form_for of @a? Then I get a nested <form> which doesn''t make any sense htmlicly speaking. -fREW --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > Well, that works really well, but what if I want that INSIDE of the > form_for of @a? Then I get a nested <form> which doesn''t make any > sense htmlicly speaking. >I said *fields_for* not form_for. It will work inside the form tag. -- Appreciated my help? Recommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ah, sorry. Thanks much! On May 21, 12:42 am, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Well, that works really well, but what if I want that INSIDE of the > > form_for of @a? Then I get a nested <form> which doesn''t make any > > sense htmlicly speaking. > > I said *fields_for* not form_for. > > It will work inside the form tag. > > -- > Appreciated my help? > Recommend me on Working With Railshttp://workingwithrails.com/person/11030-ryan-bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---