我在Rails应用程序中的视图上有一个button_to
函数,该函数当前在控制器中调用方法,但我也希望它也执行一些JavaScript。我想提示用户输入一些信息,这些信息将发送回控制器并在以后使用
这是我当前的代码。
<%= button_to 'Mark Learned' , song_rank_marklearned_path(song_rank_id: song_rank.id), remote: true , method: :post, onclick: "marklearned(#{song_rank.id})" %>
答案 0 :(得分:0)
在html.erb文件中的脚本标签内,您可以编写一些自定义JS。
<script>
function marklearned() {
var songRankId = <%= song_rank.id %> // This can reference your helper_method or instance variable
// fetch call to post to your db
}
</script>