开发者

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

开发者 https://www.devze.com 2023-03-06 06:58 出处:网络
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 im

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

精彩评论

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