Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a class to a link_to is breaking the link

I'm using link_to in RoR 3

When I use it like this, it works fine:

<%= link_to "Add to your favorites list",:controller =>              'favourite_companies', :action =>'create',              :company_id=>"#{@company.id}",                :company_name=>"#{@company.company_name}" %> 

But I would like to pass in a class as well

however, this is not working for me. The class works, but it breaks the link. Any ideas?

<%= link_to "Add to your favorites list",{:controller =>              'favourite_companies', :action =>'create'},              :company_id=>"#{@company.id}",                :company_name=>"#{@company.company_name}",             :class=>"ui-button-text button_text"}  %> 
like image 354
mtay Avatar asked Apr 18 '11 00:04

mtay


1 Answers

<%= link_to "Add to your favorites list",{:controller =>              'favourite_companies', :action =>'create'},              :company_id=>"#{@company.id}",                :company_name=>"#{@company.company_name}",             :class=>"ui-button-text button_text"}  %> 

try this

<%= link_to "Add to your favorites list", :controller =>              'favourite_companies', :action =>'create',              :company_id=>"#{@company.id}",                :company_name=>"#{@company.company_name}",             { :class=>"ui-button-text button_text" }  %> 

Since the :class should be in :html_options (refering to API)

link_to(body, url, html_options = {}) 
like image 84
edthix Avatar answered Sep 25 '22 20:09

edthix