【问题标题】:Rails button_to - applying css class to buttonRails button_to - 将 CSS 类应用于按钮
【发布时间】:2012-12-16 22:16:56
【问题描述】:

这很愚蠢,但我不知道如何设置 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>

而我想要的只是input 拥有class = "btn btn-small"

帮助?谢谢!

【问题讨论】:

    标签: ruby-on-rails forms erb button-to


    【解决方案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'} %>
    

    【讨论】:

      【解决方案2】:

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

      form_class:表单的类

      class : 表单中按钮的类

      【讨论】:

      • FWIW,这对我有用,接受的答案没有。
      猜你喜欢
      • 2013-07-30
      • 1970-01-01
      • 2014-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多