Hello, I''ve got the following model objectA 1 <------> 0..* objectB 0..* <-------> 1 objectC I''d like the url GET /objectA/1/objectC to show all objectC associated with objectA through objectB In routes.rb map.resources :objectAs, :has_many => [:objectCs] or map.resources :objectAs do |:objectA| objectA.resources :objectCs end shows me all objectCs not just those associated with objectA through objectB How can I get all objectCs associated with objectA using the url GET / objectA/1/objectC? Also if I had the following model objectA 0..* <-------> 0..* objectC How can I get all objectCs associated with objectA using the url GET / objectA/1/objectC? Thanks, ewan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller
2007-Dec-19 18:04 UTC
Re: map.resource :has_many :through :has_and_belongs_to_many
map.resources :objectAs do |:objectA| objectA.resources :objectCs end this should work, after correcting this typo: |:objectA| should |objectA| then in your action: oa = ObjectA.find(params[:objectA_id]) the objectC should simply be: oa.objectCs if you have setup the has_many and belongs_to stuff in the models but: your naming conventions are very bad for RoR (if this is not for fast typing this example). you will run in lots of trouble that way and i''m not sure, if the stuff would work the way i typed it. variable names are always lowercase eg: object_a only classnames are camelcase eg: ObjectA and it''s important to keep the rules for singular/plural namings -- 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-/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 -~----------~----~----~----~------~----~------~--~---
gemblon (t.b.)
2007-Dec-19 18:10 UTC
Re: map.resource :has_many :through :has_and_belongs_to_many
Thorsten Mueller wrote:> map.resources :objectAs do |:objectA|> > but: > your naming conventions are very bad for RoR (if this is not for fast > typing this example). you will run in lots of trouble that way and i''m > not sure, if the stuff would work the way i typed it. > > variable names are always lowercase eg: object_a > only classnames are camelcase eg: ObjectA > > and it''s important to keep the rules for singular/plural namingsi did not know you could do that with routes.rb i always had it in the model -- 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-/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 -~----------~----~----~----~------~----~------~--~---