0
0

【Rails】button_to_functionが使用できない

Posted at

はじめに

Railsのアップデート中にbutton_to_functionを使用している箇所でエラーが出たので、その対応をまとめます。

問題

以下のように、button_to_functionを使用するとエラーがでます。

<%= button_to_function "ボタン", "clickButton()", {:class=> "button"} %>

解決方法

button_to_functionはRails4.1で削除されました。
javascriptなどでボタンをクリックしたときのコードを実装します。

<a href="#" id="button" class="button">ボタン</a>

$(document).ready(function() {
  $("#button").click(function() {
    clickButton();
  });
})

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0