Nathan Farrar
2006-Sep-18 21:03 UTC
Controller & Multiple Models (And a self-referencing model!)
I''m new to rails, trying to get a basic understanding and I''ve encountered two concepts I can''t wrap my head around and can''t find answers for elsewhere. I''ve been looking for answers for hours and can''t seem to get anywhere. I apologize in advance for the really basic questions. I have a database with three tables: users items item_types I''ve generated three models: User Item ItemType I''ve generated one controller so far: Admin Now, if I can generate a scaffold for my Admin controller using any single model, but how about all three? Typically the directory structure is: application/controller/action But what if I want: application/controller/subapp/action Basically, I''d like to generate scaffolds for: /admin/user/list (edit/new/delete/show, etc) /admin/item/list (edit/new/delete/show, etc) /admin/itemtype/list (edit/new/delete/show, etc) Is this possible? If not, what is the alternative? Second, my Item model contains an integer field "parent." The field contains either 0 or a valid item_id ... so it''s self referencing. Some items belong to other items. I know how to setup a has_one or has_many relationship using different models, but how do I specify that the product field points back to another model (if it does not contain 0)? -- 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 -~----------~----~----~----~------~----~------~--~---
Nathan Farrar
2006-Sep-19 16:05 UTC
Re: Controller & Multiple Models (And a self-referencing mod
Sorry to bump myself. Hoping someone may have an answer though. 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-/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 -~----------~----~----~----~------~----~------~--~---
Pete Wright
2006-Sep-25 20:12 UTC
Re: Controller & Multiple Models (And a self-referencing mod
Not entirely sure I have a good grasp on your question, but here goes. First up, yes you can access any model from any controller. Controllers tend to span models in producing and manipulating data for the view. If you''re talking about creating controllers for each model under a common admin entry point, you can do that script/generate controller admin/Usercontroller script/generate controller admin/Itemcontroller and so on try it in a test project and you''ll see what I mean. Hope that helps?! -------------------------------------------------- Peter Wright froogle-jY3Lu0o19T39IxVxf2VSKA@public.gmane.org Personal Blog -> http://peterwright.blogspot.com Agile Development Blog -> http://exceeding-expectations.blogspot.com On 19 Sep 2006, at 12:05, Nathan Farrar wrote:> Sorry to bump myself. Hoping someone may have an answer though. > 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-/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 > -~----------~----~----~----~------~----~------~--~---