I’m building my first Rails application, and things are going OK for the
most part except for stupid little stuff like this that I simply can’t
figure out (it’s always the little things, isn’t it?).
<% for p in @pages %>
<li<% if (params[:id] == p.id) %> class=“current”<% end %>><%=
link_to(p.name.capitalize, :action => ‘edit’, :id => p) %>
<% end %>
As you can see, I want a CSS class echoed when the current ID (from
params[:id]) is the same as the ID of the page in the iteration.
However, the if(params[:id] == p.id) never seems to evaluate to true. I
have output both params[:id] and p.id in the view, and even when they’re
both outputting the same number it never evaluates to true.
What am I missing? Is there a better way to do this? Thanks!