开发者

Prevent a part of my .js.erb file from running

I have this in my create.js.erb file:

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>');
}

The problem is that in my controller, I have some conditions that if true, prevents the @showable_video object from being created. Even if this happens, the create.js.erb file is still rendered, and so there is an error because @showable_video is nil.

I'm thinking that a solution to this might be to check if 开发者_运维问答@showable_video is nil in the create.js.erb file and if it is, not run the rest of the jquery code. How can I accomplish this?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜