In my app, I need to perform transactions with external web sites. (Assume this is a system for placing online orders with restaurants -- it isn''t, but the true purpose will be revealed eventually). Each restaurant''s online system is slightly different, requiring slightly different information from the user. What I want is a landing page where all the restaurants are listed in a pull-down list. Upon selecting a specific restaurant, the user gets a view (more likely a partial) for that specific restaurant where they can enter information. To pull this off, I think I want a generic Model, View and Controller for a Restaurant, and then sub-classes for specific restaurants. I''d prefer not to hard-code the restaurant classes into a file -- it would be better if simply adding the restaurant class files to a directory caused it to get discovered by the app. And since there can be an arbitrary number of restaurants, I really don''t want them in the top-level models / controllers / views directories. My question is really about how to structure the classes and directories. What''s the idiom for doing this kind of thing in Rails? Are there good examples worth emulating? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-28 15:26 UTC
Re: best practices for sub-modules and sub-views?
Fearless Fool wrote in post #971084:> In my app, I need to perform transactions with external web sites. > (Assume this is a system for placing online orders with restaurants -- > it isn''t, but the true purpose will be revealed eventually).It''s really hard to provide accurate advice with inaccurate information.> Each > restaurant''s online system is slightly different, requiring slightly > different information from the user. > > What I want is a landing page where all the restaurants are listed in a > pull-down list. Upon selecting a specific restaurant, the user gets a > view (more likely a partial) for that specific restaurant where they can > enter information.That''s easy enough.> > To pull this off, I think I want a generic Model, View and Controller > for a Restaurant, and then sub-classes for specific restaurants.No, you probably don''t. What you probably want is a fairly generic Restaurant object with some sort of configuration property.> > I''d prefer not to hard-code the restaurant classes into a file -- it > would be better if simply adding the restaurant class files to a > directory caused it to get discovered by the app. And since there can > be an arbitrary number of restaurants, I really don''t want them in the > top-level models / controllers / views directories. > > My question is really about how to structure the classes and > directories. What''s the idiom for doing this kind of thing in Rails? > Are there good examples worth emulating?You can use namespaced models, views, and controllers. But your architectural approach is almost certainly wrong. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Marnen Laibow-Koser wrote in post #971089: [snip]> That''s easy enough.[snip]> No, you probably don''t [want a generic Model, View and Controller > for a Restaurant, and then sub-classes for specific restaurants]. > What you probably want is a fairly generic Restaurant object with > some sort of configuration property.[snip]> You can use namespaced models, views, and controllers. But your > architectural approach is almost certainly wrong.Marnen: Methinks you keep your copious wisdom too under wraps. You answer makes it clear that you think my approach is wrong, but doesn''t really explain Marnen''s One True Way! :) A search for site:http://guides.rubyonrails.org/ namespace shows me about namespaced routes, namespaced forms, but nothing about how to organize files and classes to have namespaced models, views and controllers. Perhaps my question is too general, so I can re-frame it: is there an example (on github or in Rails itself) that shows a good way to do this kind of thing? TIA. - ff -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-28 22:10 UTC
Re: best practices for sub-modules and sub-views?
Fearless Fool wrote in post #971153:> Marnen Laibow-Koser wrote in post #971089: > [snip] >> That''s easy enough. > [snip] >> No, you probably don''t [want a generic Model, View and Controller >> for a Restaurant, and then sub-classes for specific restaurants]. >> What you probably want is a fairly generic Restaurant object with >> some sort of configuration property. > [snip] >> You can use namespaced models, views, and controllers. But your >> architectural approach is almost certainly wrong. > > Marnen: > > Methinks you keep your copious wisdom too under wraps. You answer makes > it clear that you think my approach is wrong, but doesn''t really explain > Marnen''s One True Way! :)What part was unclear? I''ll be happy to elaborate.> > A search for > > site:http://guides.rubyonrails.org/ namespace > > shows me about namespaced routes, namespaced forms, but nothing about > how to organize files and classes to have namespaced models, views and > controllers.Use directories corresponding to the namespaces; that way the autoloader knows where to find the files.> > Perhaps my question is too general, so I can re-frame it: is there an > example (on github or in Rails itself) that shows a good way to do this > kind of thing? > > TIA.There should be lots of explanations of dealing with namespaced classes in Rails.> > - ffBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Marnen Laibow-Koser wrote in post #971154:> What part was unclear? I''ll be happy to elaborate. > [snip] > There should be lots of explanations of dealing with namespaced classes > in Rails.I agree that there SHOULD be! :) But I haven''t found one yet. If you give me a pointer to one good explanation about how to structure namespaced classes, I''ll be happily preoccupied for a day or two. Thanks in advance. - ff -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.