Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用button_或button_标记传递参数_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 使用button_或button_标记传递参数

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

我目前正在开发RubyonRails应用程序,我在使用button_to或button_标记传递参数方面遇到了问题

情况是,我无法使用button_标记传递参数,或者使用button_传递参数时,我无法转到我的控制器,它显示“AuthenticityToken”

是否有任何方法或正确的方法使用按钮将参数传递给控制器

        <%= 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'" %>