我试图让用户收藏帖子,然后通过 AJAX 向他们展示某种交互,但它不起作用。
我在控制台中遇到的错误是:
ActionView::Template::Error (undefined local variable or method `post_item' for #<#<Class:0x007fecb2a3d5f8>:0x007fecb2a357e0>):
该按钮正在通过部分呈现:
<%= render "shared/fave_form", post_item: post_item %>
这是按钮的代码 (shared/_fave_form.html.erb):
<% if current_user.voted_on?(Post.find(post_item)) %>
<%= link_to "unlike", vote_against_post_path(post_item.id), :remote => true, :method => :post, :class => "btn") %>
<% else %>
<%= link_to "like", vote_up_post_path(post_item.id), :remote => true, :method => :post, :class => "btn") %>
<% end %>
这是 toggle.js.erb 文件:
$("#fave").html("<%= escape_javascript render('fave_form') %>");