Search code examples
ruby-on-railslink-to

Adding :class to link_to that has :controller and :method


The below works, but I'd lie to add a class to it.

<%= link_to "Cancel My Subscription", {:controller => :charges, :action => :cancel}, {:method => :post } %>

This is not working:

<%= link_to "Cancel My Subscription", {:controller => :charges, :action => :cancel}, {:method => :post }, :class => "btn" %>

Solution

  • The way to add a class to a link is as follows:

    <%= link_to "Cancel My Subscription", { URL_FOR PARAMS HERE }, :controller => 
            :charges, :action => :cancel, :method => :post, :class => "btn" %>
    

    Hope this helps.