twitter-bootstrap 使用 HAML button_to 使用 twitter bootstrap
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18129886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting a HAML button_to work with twitter bootstrap
提问by Dsel
I am trying to apply some basic formatting to a Ruby on Rails app using Twitter Bootstrap. I would like to create a button group with three buttons but am having trouble with my haml file.
我正在尝试使用 Twitter Bootstrap 将一些基本格式应用于 Ruby on Rails 应用程序。我想创建一个包含三个按钮的按钮组,但我的 haml 文件有问题。
After looking through all the Twitter Bootstrap Documentation, I think the problem is that the bootstrap style-sheet is expecting <button>elements (with the proper classes) to place in the button group.
在浏览了所有 Twitter Bootstrap文档之后,我认为问题在于引导样式表期望<button>元素(具有适当的类)放置在按钮组中。
I am currently using the button_tohelper in my haml file which does not appear to produce the <button>tag. But, I am not experienced enough in haml to know a way around this.
我目前button_to在我的 haml 文件中使用helper,它似乎没有生成<button>标签。但是,我在 haml 方面的经验不足,无法解决这个问题。
Is there a way to make the button_toelement generate a <button>tag, or should I be attacking this problem in a different way?
有没有办法让button_to元素生成<button>标签,或者我应该以不同的方式解决这个问题?
回答by Jeff LaJoie
If you're trying to get a button tag in HAML you can use the %buttontag to generate it.
如果您尝试在 HAML 中获取按钮标签,您可以使用该%button标签来生成它。
In order to change the class you would be able to do %button.class
为了改变班级,你将能够做到 %button.class
ex.
前任。
%button.alert Test
%button.alert Test
Would generate
会产生
<button class="alert">Test</button>
EDIT:
编辑:
Just a bit extra, while I'm not experienced with using Bootstrap (I used Foundation), if you're interested in using button_toyou're allowed to declare the class, though it won't generate the tag you're looking for so this part is not related to your question.
只是有点额外,虽然我没有使用 Bootstrap 的经验(我使用过 Foundation),但如果您有兴趣使用,button_to您可以声明该类,尽管它不会生成您正在寻找的标签这部分与您的问题无关。
= button_to 'Example, {:controller => 'your_controller', :action => 'your_action'}, {:class => 'your button class', :method => 'post'}
However this will generate a
然而这会产生一个
<input class="small button" type="submit" value="Example">

