Adding bootstrap button class to button_to in rails 4

白昼怎懂夜的黑 提交于 2019-12-20 02:17:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!