防止我的.js.erb文件从我create.js.erb文件运行

问题描述:

我有这样的一个部分:防止我的.js.erb文件从我create.js.erb文件运行

if ($(".none").length){ 
    $(".none").replaceWith('<ul class="shown_users_list"><li id="<%= dom_id(@showable_video) %>"><%= link_to image_tag(@showable_video.profile.photo.url(:thumbnail)), profile_path(@showable_video.profile), :class => "feed_image"%><%= link_to "#{@showable_video.profile.user.name}", profile_path(@showable_video.profile), :class => "normal squeeze" %><%= link_to image_tag("/images/facebox/closelabel.gif"), showable_video_path(@showable_video), :method => :delete, :remote => true, :class => "showable_video_delete" %></li></ul>'); 
} 
else{ 
    $("ul.shown_users_list").append('<li id="<%= dom_id(@showable_video) %>"><%= link_to image_tag(@showable_video.profile.photo.url(:thumbnail)), profile_path(@showable_video.profile), :class => "feed_image"%><%= link_to "#{@showable_video.profile.user.name}", profile_path(@showable_video.profile), :class => "normal squeeze" %><%= link_to image_tag("/images/facebox/closelabel.gif"), showable_video_path(@showable_video), :method => :delete, :remote => true, :class => "showable_video_delete" %></li>'); 
} 

的问题是,在我的控制,我有一些条件,如果属实,防止创建对象@showable_video。即使发生这种情况,create.js.erb文件仍然呈现,所以出现错误,因为@showable_video为零。

我在想这个解决方案可能是检查@showable_video是否在create.js.erb文件中,如果是,则不运行其余的jquery代码。我怎样才能做到这一点?

<% if @showable_video %> 
    ... your code here 
<% end %> 
+0

咄......... -_- – user730569 2011-05-15 23:16:47

+0

标识甚至是其他块添加到输出 – DGM 2011-05-16 01:50:57

+0

AHH有趣的错误什么的,是的,我会做到这一点...谢谢 – user730569 2011-05-16 01:51:45