我有一个“index.html.erb”文件,其中包含以下内容:
<%= 渲染@users %>
这将呈现“_user.html.erb”并输出一个用于对每个用户执行特定操作的按钮:
<%= link_to "action", action_path(user), :id => "#{user.id}_action", :remote => true) %>
我已经设置我的用户控制器通过查看“action.js.erb”来响应 AJAX 请求。
为了对部分中的特定用户执行 javascript 方法,我想知道如何将部分中的实例变量(例如 user.id)传递到 js.erb 文件中或在其中访问,例如:
$("#{@user.id}_action").toggle();