2011-05-15 13 views
0

我有這樣的一個部分:防止我的.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代碼。我怎樣才能做到這一點?

回答

0
<% 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

相關問題