Rails button_to - applying css class to button

南楼画角 提交于 2019-12-18 05:27:38

问题


This is silly, but I just can't figure out how to style the input element created by Rails button_to -- and yes, I've read the docs over and over again and tried the samples.

Here's my ERB code:

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

And this yield the following 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>

Whereas all I want is just input to have class = "btn btn-small".

Help? Thank you!


回答1:


The signature of the method button_to is

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

So use {} to distinguish options and html_options

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



回答2:


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

form_class: class for the form

class : class for button in the form



来源:https://stackoverflow.com/questions/14123884/rails-button-to-applying-css-class-to-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!