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

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 K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

Dan K. 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 K. mailto:[email protected]
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.