Ok here''s a quicky... but a goody :) We have models Company, Reference and Applicant... and References and Applicants just inherit from Company, and are basically companies with the type field set to reference... All companies can have a phone number associated with them, and phone number is a different model... I''m having trouble using the form_for method with a company that happens to be an Applicant... form_for( [ @company, @phone_number] ) tries to use the route applicant_phone_number however the only route that exists is company_phone_number, which is the one I want to use... I tried to create a route by creating a map.resource :applicants, :has_many => phone_numbers but there is no resource for Reference or Applicant only models, and thus it breaks down... I get errors. Any ideas on the correct way to make this work? --~--~---------~--~----~------------~-------~--~----~ 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 Nov 4, 9:46 am, sw0rdfish <san...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok here''s a quicky... but a goody :) > > We have models Company, Reference and Applicant... and References and > Applicants just inherit from Company, and are basically companies with > the type field set to reference... > > All companies can have a phone number associated with them, and phone > number is a different model... > > I''m having trouble using the form_for method with a company that > happens to be an Applicant... > > form_for( [ @company, @phone_number] ) > > tries to use the route applicant_phone_number however the only route > that exists is company_phone_number, which is the one I want to use...Yup, using an array in form_for doesn''t work in STI situations like you''ve got. You''ll have to do something like: form_for :company_phone_number_path(@company, @phone_number) Jeff www.purpleworkshops.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-/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 -~----------~----~----~----~------~----~------~--~---
Ok so I tried your way, and I got an error; compile error syntax error, unexpected ''('', expecting kEND _erbout = ''''; form_for :company_phone_number_path( [@company, @phone_number] ) do |f| ; _erbout.concat "\n" So I did a little digging to see the syntax for it, and I came up with <% form_for( [:company, @trade_item] ) do |f| %> which seems to do the trick! Quick Q, what does STI stand for, and what''s the proper syntax for your "version" ? On Nov 4, 3:33 pm, Jeff <cohen.j...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Nov 4, 9:46 am, sw0rdfish <san...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Ok here''s a quicky... but a goody :) > > > We have models Company, Reference and Applicant... and References and > > Applicants just inherit from Company, and are basically companies with > > the type field set to reference... > > > All companies can have a phone number associated with them, and phone > > number is a different model... > > > I''m having trouble using the form_for method with a company that > > happens to be an Applicant... > > > form_for( [ @company, @phone_number] ) > > > tries to use the route applicant_phone_number however the only route > > that exists is company_phone_number, which is the one I want to use... > > Yup, using an array in form_for doesn''t work in STI situations like > you''ve got. > > You''ll have to do something like: > > form_for :company_phone_number_path(@company, @phone_number) > > Jeff > > www.purpleworkshops.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-/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 -~----------~----~----~----~------~----~------~--~---
On Nov 4, 3:09 pm, sw0rdfish <san...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok so I tried your way, and I got an error; > > compile error > syntax error, unexpected ''('', expecting kEND > _erbout = ''''; form_for :company_phone_number_path( [@company, > @phone_number] ) do |f| ; _erbout.concat "\n" > > So I did a little digging to see the syntax for it, and I came up with > > <% form_for( [:company, @trade_item] ) do |f| %> > > which seems to do the trick!Interesting! I should have known that: by using the symbol, instead of an @ variable, it just uses the name ''company'' instead of trying to inspect the @company class name.> Quick Q, what does STI stand for, and what''s the proper syntax for > your "version" ?Sorry: STI = "Single Table Inheritance", the Rails term for using the "type" column in your table to help Rails figure out the right subclass for the object corresponding to that row in the table. I think you''re getting the syntax error because you''re still using the array form [@company, @phone]. I just use company_phone_path(@company, @phone) where @company and @phone are just passed as regular arguments. Jeff --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---