2013-01-02 105 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:按鈕形式的類