I’m using a bog standard .find(:all) in my controller which the <% for
%> loop in my view then displays the results of.
How can I apply a different css style (class or id) to the first result
that my view returns? and then subsequently the 2nd and 3rd (basically
Gold, Silver, Bronze). All the rest just use a generic style.
I’m using a bog standard .find(:all) in my controller which the <% for
%> loop in my view then displays the results of.
How can I apply a different css style (class or id) to the first
result
that my view returns? and then subsequently the 2nd and 3rd (basically
Gold, Silver, Bronze). All the rest just use a generic style.
You just need to track which row you’re on. If you use render :partial
then you automatically get an index variable (if the partial is foo
then you get foo_counter)
Personally, I hate <% for %> and prefer to go with the underlying <%
each %>… and for your purpose you might also consider using <%
each_with_index %>. Combine that with Rob’s suggestion and you can
use the index from the loop to index the medal_class hash.
(basically
Gold, Silver, Bronze). All the rest just use a generic style.
You just need to track which row you’re on. If you use render :partial
then you automatically get an index variable (if the partial is foo
then you get foo_counter)
Fred
You could use a hash with a default value and index it with the
position:
If you follow Fred’s advice and use a partial for a row, then the
*_counter will be a good choice. If you have a simple loop
with .each_with_index {|thing,index| … }, then you’d have to adjust
0=>‘Gold’, etc. to match the zero-based array index.