加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails button_to – 将css类应用于按钮

发布时间:2020-12-16 20:39:12 所属栏目:百科 来源:网络整理
导读:这是愚蠢的,但我无法弄清楚如何对由Rails button_to创建的输入元素进行风格化,而且,我已经一遍又一遍阅读了文档,并尝试了这些示例. 这是我的ERB代码: %= button_to "Claim",action: "claim",idea_id: idea.id,remote: true,class: 'btn btn-small' % 这样产
这是愚蠢的,但我无法弄清楚如何对由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>

而所有我想要的只是输入有class =“btn btn-small”.

帮帮我?谢谢!

解决方法

方法 button_to的签名是
button_to(name = nil,options = nil,html_options = nil,&block)

所以使用{}区分选项和html_options

<%= button_to "Claim",{action: "claim",remote: true},{class: 'btn btn-small'} %>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读