Techioz Blog

button_to または button_tag を使用してパラメータを渡します

概要

現在Ruby on Railsアプリに取り組んでいますが、button_toまたはbutton_tagを使用したパラメータの受け渡しに関して問題が発生しています

シナリオは、button_tag を使用してパラメーターを渡すことができないか、button_to を使用するとコントローラーにアクセスできないというもので、「AuthenticityToken」と表示されます。

ボタンを使用してコントローラーにパラメータを渡す方法または適切な方法はありますか?

        <%= button_tag "Update", :type => 'button', :class => "btn btn-info", :onclick => "location.href = 'student/displayStudent'" , params: {id: student.student_name}%>

ありがとう。

解決策

これを試して:

<%= button_tag "Update", :name => 'id', :value => student.student_name, :type => 'button', :class => "btn btn-info", :onclick => "location.href = 'student/displayStudent'" %>