2013-05-02 45 views
0

我使用稱爲auto_html的gem嵌入了soundcloud網址。偶爾我的網站會隨機崩潰,這個錯誤似乎是來自Soundcloud上過多流量的超時請求?有什麼辦法可以忽略當代碼超時並重新加載頁面時嵌入文件的代碼行嗎?可能會忽略一行代碼並在崩潰時重新加載頁面?

錯誤:

JSON::ParserError 

ActionView::Template::Error (757: unexpected token at '<!DOCTYPE HTML PUBLIC 
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

      We were unable to process your request in time - SoundCloud 
      Yikes, we were unable to process your request in time. 
      Please reload the page or try again in a moment. 

代碼在視圖中被忽略:

41:  <% if micropost.url.include? 'soundcloud' %> 
42:   <%= auto_html(micropost.url) {soundcloud} %> 
43:  <% end %> 

回答

0

我想你可以創建一個輔助方法,將「執行」的auto_html輔助方法,並返回結果。在這種方法中,你可以用開始,救援和錯誤來包圍調用,你可以返回一個js來做一個重載(window.location.href ...)。

我不知道你是否可以通過輔助方法重定向,如果是的話就更容易了。

+0

我可以只使用rails redirect_to方法,我想?如果你有時間,我可以給你一個如何在失敗時使用救援的例子 – Jaqx 2013-05-03 02:41:39

相關問題