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
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| %>
<%= event.name %>
<% 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?