2013-09-27 22 views
0

我想我的應用程序重定向到我的主頁,即帖子#索引。這是我想遷移rails2應用軌道3重定向rails應用程序崩潰的主頁

def rescue_action_in_public(exception) 
    flash[:notice] = "There was an error. Please try again." # #{exception} 
    redirect_to :controller => :posts, :action => :index 
end 

這個方法我相信做這個任務。如何,它不會在rails 3中工作,我看到'抱歉出錯了!'頁面

如何在rails 3中使用此功能?如果有更多的信息,需要我願意粘貼在這裏。

回答

0

在軌道3試試這個

def rescue_action_in_public(exception) 
     status = status_code(exception) 
     locale_path = "#{public_path}/#{status}.#{I18n.locale}.html" if I18n.locale 
     path = "#{public_path}/#{status}.html" 

     if locale_path && File.exist?(locale_path) 
      render(status, File.read(locale_path)) 
     elsif File.exist?(path) 
      render(status, File.read(path)) 
     else 
      render(status, '') 
     end 
     end 

apidock

0

您可以右鍵這樣!

def rescue_action_in_public(exception) 
    flash[:notice] = "There was an error. Please try again." # #{exception} 
    redirect_to posts_path 
end