2017-07-06 46 views
0

我正在嘗試使用一個id和一個帶有rails的類來構建一個按鈕。點擊按鈕時會觸發一個javascript事件。我嘗試了不同的東西,他們都沒有在所有的盒子上打勾。rails button_tag與button_to - class&id

<%= button_tag "Launch the js event", id: "button-feedback-by-bullet" %> 

這工作,但沒有課

<%= button_tag "Launch the js event", id: "button-feedback-by-bullet", class: "btn-primary" %> 

我得到一個錯誤說有太多的爭論

<%= button_to "Launch the js event", id: "button-feedback-by-bullet", class: "btn-primary" %> 

我得到正確的類,但按鍵通過POST方法和js事件不會被解僱

你能幫我找到正確的語法和聯合國denstand button_tag和button_to之間的細微差別?謝謝。

回答

1

button_tag(content_or_options =零,選擇=零,&塊)公共

你應該做

<%= button_tag "Launch the js event", {id: "button-feedback-by-bullet", class: "btn-primary"} %> 

button_to

button_to(名稱=零,options = nil,html_options = nil,&聯盟K)

<%= button_to "Launch the js event", {}, {id: "button-feedback-by-bullet", class: "btn-primary"} %> 

此外,button_tagbutton_to觸發submit默認,也許你應該使用link_to代替