What''s the right RoR way if a controller needs to display one of many views in, say, an index method? -- 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.
Ralph Shnelvar wrote:> What''s the right RoR way if a controller needs to display one of many > views in, say, an index method?You can use render or redirect_to. But why would an index method need this? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. --0015174c3ff232df0d047d713978 Content-Type: text/plain; charset=ISO-8859-1 -- 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. --0015174c3ff232df0d047d713978--
2010/1/18 Ralph Shnelvar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> What''s the right RoR way if a controller needs to display one of many > views in, say, an index method?Do you mean you want several different views all of which are ''index'' views but arranged differently? If so then one method is to pass parameters to the index action via the url to determine which data and view to show. Colin -- 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.
For each controller in the line, it''s defined methods be actions for the implicit render of the view with the names that match def and view, If you write this way, you''ll save some typing If you practice everyday, you may find a better way. If you want to write about a Resource, it helps to think about and read into REST. It makes most sense when you have a noun. non-rest Controller BakeriesController host:port/bakeries/index host:port/bakeries/by_city host:port/bakeries/that_have_nice_scones REST resource PicklesController host:port/pickles/index/ host:port/pickles/show/1 On Mon, Jan 18, 2010 at 6:24 AM, Ralph Shnelvar <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> What''s the right RoR way if a controller needs to display one of many > views in, say, an index method? > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > >-- 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.
I would second Colin''s suggestion. Basically, you use some clue (URL parameter, session, database state or any external data) to decide what to render at the moment. If I needed such a thing, my approach would be to have several index partials or templates that I would render selectively. The naming would be _index_standard.xyz, _index_specific_1.xyz or something along these lines. Obviously, I wouldn''t put the selection logic in the view itself. - Aleksey On Jan 19, 1:34 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2010/1/18 Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>: > > > What''s the right RoR way if a controller needs to display one of many > > views in, say, an index method? > > Do you mean you want several different views all of which are ''index'' > views but arranged differently? If so then one method is to pass > parameters to the index action via the url to determine which data and > view to show. > > Colin-- 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.