У меня есть это в моем файле 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>');
}
Проблема в том, что в моем контроллере есть некоторые условия, которые, если true, препятствуют созданию объекта @showable_video
. Даже если это произойдет, файл create.js.erb по-прежнему будет отображаться, и поэтому возникает ошибка, поскольку @showable_video
равно nil.
Я думаю, что решением этой проблемы может быть проверка, является ли @showable_video
нулем в файле create.js.erb, и, если это так, не запускать остальную часть кода jquery. Как мне это сделать?