Rails link_to assigning class and id

Dudo picture Dudo · Jan 11, 2013 · Viewed 24.1k times · Source
<%= link_to event do  %>
  #bunch of stuff making up the partial.
<% end %>

So I'm trying to assign an ID and a class to each item in a partial. I've seen where you have to call the full link_to function like <%= link_to event, { controller: :controller, action: :action }, {class: 'someClass', id: 'someId' } %>.

That's not working for me, because of the do block, methinks? Ideas?

Answer

Ben picture Ben · Jan 11, 2013

Does this work for you?

<%= link_to event, id: "an-id", class: "some-class" do  %>
  #bunch of stuff making up the partial.
<% end %>