J Jones
2006-Jul-23 18:51 UTC
[Rails] How would you do this without using render_component
Hello all. Am relatively new to RoR and I am pondering how to do something without using components since they appear to be "coda non grata". I have a standard layout that is used by all controllers. In this layout I want to list the next 5 events that are upcoming based on todays date. These events are currently stored in the Event model (created using scaffolding). Currently only the Events controller accesses the Event model. Currently the layout uses the following <%= render_component(:controller => ''events'', :action => ''upcoming'') %> Which is an action that retrieves the next 5 events and renders a partial to put them in list format. The only option I can see is move the retrieval code into the model then have something along the lines of <% Event.upcoming do |event| %> //html code <%= event.name %> //html code <% end %> In the layout view. This seems to fly in the face of the "Put as little code in the views as possible" mantra I see all over the ruby community so I am not quite sure how to handle this. Does anyone have any insightful way of doing this? Many thanks Jeff -- Posted via http://www.ruby-forum.com/.
Dan Kohn
2006-Jul-23 21:10 UTC
[Rails] How would you do this without using render_component
Put the controller code in application.rb and then call it from each controller where you need it, using a before or after filter. - dan -- Dan Kohn <mailto:dan@dankohn.com> <http://www.dankohn.com/> <tel:+1-415-233-1000> On Jul 23, 2006, at 11:51 AM, J Jones wrote:> Hello all. > > Am relatively new to RoR and I am pondering how to do something > without > using components since they appear to be "coda non grata". > > I have a standard layout that is used by all controllers. In this > layout > I want to list the next 5 events that are upcoming based on todays > date. > > These events are currently stored in the Event model (created using > scaffolding). Currently only the Events controller accesses the Event > model. > > Currently the layout uses the following > > <%= render_component(:controller => ''events'', :action => > ''upcoming'') %> > > Which is an action that retrieves the next 5 events and renders a > partial to put them in list format. > > The only option I can see is move the retrieval code into the model > then > have something along the lines of > > <% Event.upcoming do |event| %> > //html code > <%= event.name %> > //html code > <% end %> > > In the layout view. This seems to fly in the face of the "Put as > little > code in the views as possible" mantra I see all over the ruby > community > so I am not quite sure how to handle this. > > Does anyone have any insightful way of doing this? > > Many thanks > > Jeff > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
J Jones
2006-Jul-23 22:17 UTC
[Rails] Re: How would you do this without using render_component
Dan Kohn wrote:> Put the controller code in application.rb and then call it from each > controller where you need it, using a before or after filter. > > - dan > -- > Dan Kohn <mailto:dan@dankohn.com> > <http://www.dankohn.com/> <tel:+1-415-233-1000>Many thanks, that is what I ended up doing. Glad that I wasn''t thinking totally along the wrong lines. -- Posted via http://www.ruby-forum.com/.
Apparently Analagous Threads
- Customize list.rhtml to display only certain db columns
- Views in one controller reaching out to other controllers (best practices)
- 0.9.0 Version of Gem installation problem?
- [Slightly OT] Dealing with lost connections
- Reading floating points into a field stored as Integers