2013-01-02 144 views
18

这很愚蠢,但我无法弄清楚如何设计由Rails button_to创建的输入元素 - 是的,我一遍又一遍地阅读了文档并尝试样品。Rails button_to - 将css类应用到按钮

这里是我的ERB代码:

<%= button_to "Claim", action: "claim", idea_id: idea.id, remote: true, class: 'btn btn-small' %> 

这产生以下HTML:

<form action="/ideas/claim?class=btn+btn-small&amp;idea_id=4&amp;remote=true" class="button_to" method="post"> 
    <div> 
    <input data-remote="true" type="submit" value="Claim"> 
    <input name="authenticity_token" type="hidden" value="pU3umgqrDx3WbalfNK10c9H5B5N4OzPpohs4bWW8mow="> 
    </div> 
</form> 

而所有我要的只是inputclass = "btn btn-small"

帮助?谢谢!

回答

31

方法button_to的签名是

button_to(name = nil, options = nil, html_options = nil, &block) 

因此,使用{}区分optionshtml_options

<%= button_to "Claim", {action: "claim", idea_id: idea.id, remote: true}, {class: 'btn btn-small'} %> 
+2

越来越多的我认为,Rails是惊人的! – Psylone

4

<%= button_to "Claim", {action: "claim", idea_id: idea.id, remote: true}, {form_class: 'form', class: 'btn btn-small'} %>

form_class:类形式

class:按钮形式的类