Say I have a block like this:
<% @help_sections.each do |section| %>
<li><%= section.name %></li>
<% end %>
But on the last record returned, I want to do something else, e.g. applying a class to the li
that's there:
<li class="last"><%= section.name %></li>
How do I do that in the most DRY way?
Thanks.
Edit1:
I imagine I would simply use an if
statement and the last
ruby method, but not sure how to do that within the block? I know that if I just wanted the last element in that array, I could just do @help_sections.last
, but that doesn't make sense within the confines of a Ruby block.