I'm still getting my first app going, so this i believe should be a
fairly simple problem.
My Rails (3.0.0) app displays tables of events, with columns for Date /
Band / venue / image etc.
Currently it display the data in date order, which is great, but I'd
also like to colour the table rows according to whether the date is old,
within the next month, or after 1 month from now.
I imagine I'll want to make a differnt css class for each of these, with
stuff like:
old_date {
<TD BGCOLOR="#ffff00">;
}
this_month {
<TD BGCOLOR="#ff00ff">;
}
etc...
but where in the code should I put the logic that determines which css
class to use depending on the date?
The view that displays the data is a simple table that goes through the
array:
I'd write a view helper. you might either write a helper called
something like class_for_event (and then use it like <td style=<%=
class_for_event event %>) or go for something like td_for_event which
would create a td with the right class.
Helpers go in rails_root/app/helpers. Look in there. If you used
scaffold, You should have files for controller specific helpers and a
global helper file named application_helper.rb
Cheers Dan, I'd thought those helpers were only available to the
controllers, so didn't know i could use them with the views as well,
thanks for the insight.