Reputation: 2381
I have a loop that links to every item in a collection:
<% current_user.projects.all.each do |p| %>
<%= link_to p.name, project_path(p), :class => current_class?(project_path(p)), :id => p.theme %>
<% end %>
Right now, I'm assigning a class for the anchor in addition to an id so I can apply some CSS. Really though, it would make more sense for me to have this as a double classed anchor. Is there a way to assign two classes to the same object with the link_to helper?
Upvotes: 4
Views: 8984
Reputation: 16355
Just separate them by spaces, as you would in ordinary HTML.
<%= link_to p.name, project_path(p), :class => "class1 class2 class3", :id => p.theme %>
You can generate the string however you want. If you have the classes you want as an array you could use some_classes.join(" ")
to combine them.
Upvotes: 15