Ruby on rails 使用button_或button_标记传递参数
我目前正在开发RubyonRails应用程序,我在使用button_to或button_标记传递参数方面遇到了问题 情况是,我无法使用button_标记传递参数,或者使用button_传递参数时,我无法转到我的控制器,它显示“AuthenticityToken” 是否有任何方法或正确的方法使用按钮将参数传递给控制器Ruby on rails 使用button_或button_标记传递参数,ruby-on-rails,ruby,Ruby On Rails,Ruby,我目前正在开发RubyonRails应用程序,我在使用button_to或button_标记传递参数方面遇到了问题 情况是,我无法使用button_标记传递参数,或者使用button_传递参数时,我无法转到我的控制器,它显示“AuthenticityToken” 是否有任何方法或正确的方法使用按钮将参数传递给控制器 <%= button_tag "Update", :type => 'button', :class => "btn btn-info", :onc
<%= button_tag "Update", :type => 'button', :class => "btn btn-info", :onclick => "location.href = 'student/displayStudent'" , params: {id: student.student_name}%>
'button',:class=>“btn btn info”,:onclick=>“location.href='student/displayStudent',参数:{id:student.student\u name}%>
谢谢。试试这个-
<%= button_to 'Update', {:controller => "students", :action => "displayStudent", :id => student.student_name}, :method=>:put %>
“学生”,:action=>“displayStudent”,:id=>student.student\u name},:method=>:put%>
在控制器中执行此操作(顶部)
如果你不想使用它,你可以像这样通过Javascript传递数据
$(".div").bind('click', function(){
$.ajax({
url: '/controller/'+this.value+'/action',
type: 'POST',
data: {"data": value}
});
});
我的错,我声明了一个表单,然后使用按钮与一个操作和控制器进行交互,这就是为什么它显示真实性令牌的原因
<%= button_tag "Update", :name => 'id', :value => student.student_name, :type => 'button', :class => "btn btn-info", :onclick => "location.href = 'student/displayStudent'" %>
'id',:value=>student.student\u name,:type=>'button',:class=>“btn btn info”,:onclick=>“location.href='student/displaystudio'”%>
authenticitytoken追加到url中。它没有进入我的生活controller@NikitaSingh:controller的名称始终为复数
,您需要将学生
更改为学生
,更新
方法为放置
请求类型。在开始获得其他人的反对票之前改变它
<%= button_tag "Update", :name => 'id', :value => student.student_name, :type => 'button', :class => "btn btn-info", :onclick => "location.href = 'student/displayStudent'" %>