Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a class to link_to block

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.

like image 218
mbajur Avatar asked Jul 18 '12 15:07

mbajur


2 Answers

You need to add the URL as the first parameter, then the html options, e.g.:

<%= link_to resource_path(@resource), :class => 'some_class', :method => :delete, :data => { :confirm => 'Are you sure?' }  do
  <span>Delete</span>
<% end %>
like image 190
Teoulas Avatar answered Oct 11 '22 15:10

Teoulas


I actually found this to be a working solution with Rails 4.2

<%= link_to(resource_path(@resource), class: "project-card clearfix") do %>
    <h1>Your html here</h1>
<% end %>
like image 32
dillonbailey Avatar answered Oct 11 '22 15:10

dillonbailey