cjm2671
cjm2671

Reputation: 19456

Is there a way I can control the class of the button using button_to?

It seems that :class appears to control the class of the parent form, not the button itself.

I want to add the class btn primary to the button.

If I can't do it directly, can I do it using the form class and SASS? (using @extend or something similar)?

Upvotes: 2

Views: 108

Answers (2)

iain
iain

Reputation: 16274

You need to make sure that :class => "btn primary" is the third argument of the button_to call.

If you're doing this:

<%= button_to "Hello", :action => :new, :class => "btn primary" %>

You are actually saying:

<%= button_to("Hello", { :action => :new, :class => "btn primary" }) %>

So you should change it to:

<%= button_to "Hello", { :action => :new }, :class => "btn primary" %>

I try to avoid using hashes for paths altogether, and use the generated routing methods.

<%= button_to "Hello", new_hello_path, :class => "btn primary" %>

Upvotes: 4

John
John

Reputation: 3296

This should do it

<%= button_to 'New Job', {:controller => :jobs, :action => :new}, :class => 'btn primary' %>

Upvotes: 2

Related Questions