Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling Rails button link helpers with Twitter Bootstrap

I'm using Rails helpers to generate buttons and I'm trying to style the buttons with Twitter bootstrap styles for buttons. I've added classes with the :html option. The page isn't breaking but the styles aren't showing up.

<%= button_to('Sign Up', new_user_registration_path, :html => {:class => 'btn.btn-large.btn-primary'})  %>
<%= button_to "Sign Up", user_omniauth_authorize_path(:facebook), :html => {:class => 'btn.btn-large.btn-primary'} %>

This is page source for the facebook button

<form action="/users/sign_up" class="button_to" method="post"><div><input html="{:class=&gt;&quot;btn.btn-large.btn-primary&quot;}" type="submit" value="Sign Up" /><input name="authenticity_token" type="hidden" value="QIvZqd9BRV8TMspMvckAUjhC68nm3NTyQCxVRHFA4PE=" /></div></form>
<form action="/users/auth/facebook" class="button_to" method="post"><div><input html="{:class=&gt;&quot;btn.btn-large.btn-primary&quot;}" type="submit" value="Sign Up" /><input name="authenticity_token" type="hidden" value="QIvZqd9BRV8TMspMvckAUjhC68nm3NTyQCxVRHFA4PE=" /></div></form>

any idea what I'm doing wrong?

enter image description here

like image 576
Leahcim Avatar asked Mar 31 '12 02:03

Leahcim


2 Answers

You just need :class => "foo" to set the class of the button, instead of :html => { :class => "foo" }. So it should look like this:

<%= button_to('Sign Up', new_user_registration_path, :class => 'btn btn-large btn-primary')  %>

This will generate your large primary button.

like image 153
Jeff Smith Avatar answered Oct 13 '22 18:10

Jeff Smith


The above answer got close to a fix for me but needed to change the button_to to a link_to. Also got rid of the rocket... =>

<%= button_to('Sign Up', new_user_registration_path, class: 'btn btn-large btn-primary')  %>
like image 31
Jadam Avatar answered Oct 13 '22 18:10

Jadam