はじめに
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();
});
})
参考