问题
I have a button_to call in my Rails 4 haml file that looks like this
= button_to("Click Me", action: "click", class: "btn btn-primary")
However, the class: "btn btn-primary"
code snippet isn't working properly, and my button isn't changing. I've also tried the old Ruby syntax of :class => "btn btn-primary"
, but that doesn't seem to do the trick.
Any help would be greatly appreciated.
回答1:
You need to make sure the second and third parameters to button_to are separate. Currently the action
and class
keys are being passed as a single hash, but they should be two arguments, one for options
and one for html_options
.
Try (note the extra {...}
around action: "new"
making it a separate hash):
= button_to("Click Me", { action: "new" }, class: "btn btn-primary")
来源:https://stackoverflow.com/questions/17952888/adding-bootstrap-button-class-to-button-to-in-rails-4