2017-07-06 48 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代替