Adding a class to link_to block

Viewed 7867

I have a following code which displays a 'delete' link:

<%= link_to :class => 'some_class', :method => :delete, :data => { :confirm => 'Are you sure?' }  do
  <span>Delete</span>
<% end %>

But for some reason ROR is not adding some_class to a tag. Have you any idea what can i do to fix it ? Thanks in advance.

4 Answers

If you need to pass a controller and action, like edit and destroy, do it as follow:

<%= link_to url_for(controller: controller_name, action: :edit, id: item.id), class: "btn btn-link btn-warning btn-just-icon edit" do %>
  <i class="material-icons">edit</i>
<% end %>
<%= link_to url_for(controller: controller_name, action: :destroy, id: item.id), method: :delete, data: { confirm: t('common.confirm') }, class: 'btn btn-link btn-danger btn-just-icon remove' do %>
  <i class="material-icons">close</i>
<% end %>
Related