Leahcim
Leahcim

Reputation: 42049

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

Upvotes: 10

Views: 12773

Answers (2)

Jadam
Jadam

Reputation: 1787

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')  %>

Upvotes: 1

Jeff Smith
Jeff Smith

Reputation: 902

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.

Upvotes: 18

Related Questions