在rails 4中将bootstrap按钮类添加到button_to [英] Adding bootstrap button class to button_to in rails 4

查看:89
本文介绍了在rails 4中将bootstrap按钮类添加到button_to的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Rails 4 haml文件中有一个button_to调用,如下所示

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")

但是, class: btn btn-primary 代码段无法正常工作,并且我的按钮没有更改。我还尝试了:class =>的旧Ruby语法。 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.

任何帮助将不胜感激。

推荐答案

您需要确保 button_to 是分开的。目前 action class 键是作为单个散列传递的,但是它们应该是两个参数,一个用于选项和一个 html_options

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")

这篇关于在rails 4中将bootstrap按钮类添加到button_to的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆