I have this in my create.js.erb file:
我在我的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>');
}
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.
问题是在我的控制器中,我有一些条件,如果为true,则阻止创建@showable_video对象。即使发生这种情况,仍会呈现create.js.erb文件,因此出现错误,因为@showable_video为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?
我认为解决这个问题的方法可能是检查create.js.erb文件中的@showable_video是否为nil,如果是,则不运行其余的jquery代码。我怎么能做到这一点?
1 个解决方案
#1
0
<% if @showable_video %>
... your code here
<% end %>
#1
0
<% if @showable_video %>
... your code here
<% end %>