Jquery 使用AJAX渲染的部分内容无法正常工作

Jquery 使用AJAX渲染的部分内容无法正常工作,jquery,ruby-on-rails,ruby,ajax,ruby-on-rails-3,Jquery,Ruby On Rails,Ruby,Ajax,Ruby On Rails 3,我使用AJAX呈现此部分内容: <% if current_user.profiles_shown_video.where("video_id = ?", params[:id]).count == 0 %> <p class="none"> None </p> <% else %> <ul class="shown_users_list"> <% current_user.profiles_shown_video

我使用AJAX呈现此部分内容:

<% if current_user.profiles_shown_video.where("video_id = ?", params[:id]).count == 0 %>
  <p class="none"> None </p>
<% else %>
  <ul class="shown_users_list">
    <% current_user.profiles_shown_video.where("video_id = ?", params[:id]).each do |p| %>  
      <li><%= link_to image_tag(p.photo.url(:thumbnail)), profile_path(p), :class => "feed_image"%> 
          <%= link_to "#{p.user.name}", profile_path(p), :class => "normal squeeze" %> 
          <%= link_to image_tag("/images/facebox/closelabel.gif"), showable_video_path(ShowableVideo.find_by_user_id_and_profile_id_and_video_id(current_user, p, @video)), :method => :delete, :remote => true, :class => "showable_video_delete" %></li>
    <% end %>
  </ul> 
<% end %>
这在destroy.js.erb中。它呈现包含上述第一个代码块的分部代码:

$("#shown_users_div").html('<%= escape_javascript(render("showable_videos/shown_users")) %>')
$(“#显示的_用户_div”).html(“”)

ActiveRecord缓存关联的对象。运行
@showable\u video.destroy
后,
当前用户
(本身可能正在缓存)的内存中仍将有
@showable\u video
,因此集合将非空。创建、更新或删除数据库记录后,必须运行:

current_user.reload

以便从数据库中重新加载相关对象。

需要更多上下文。您的ajax操作中运行的是什么代码?不,问题是
当前用户。配置文件显示了\u视频。其中(“video\u id=?”,params[:id])。count始终被计算为0,而实际上不应该是0,而不是集合仍然是非空的。对不起,我只是猜测。我不知道显示的
配置文件\u视频
方法是什么,也不知道您的模型上有哪些列/关联。没关系。我在想,它可能与AJAX有一些一般性的联系,而不是我的应用程序的细节。@user730569现在有人对我的答案投了反对票,你是否打算发布
配置文件的代码\u video
或你的模型,以便我有机会挽回自己的损失?
current_user.reload