Rails的button_to - 应用CSS类按钮(Rails button_to - appl

2019-07-17 18:55发布

这是愚蠢的,但我只是无法弄清楚如何风格深受Rails的创建的输入元素button_to -是的,我一遍又一遍的阅读文档,并试图将样本。

这里是我的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"

救命? 谢谢!

Answer 1:

该方法的签名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'} %>


Answer 2:

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

form_class:类形式

类:类形式按钮



文章来源: Rails button_to - applying css class to button