2014-09-22 79 views
1

我一直在类似于下面的日志中看到错误。间歇性Ruby on Rails日志(ActionView :: MissingTemplate)

任何人都可以提出为什么我可能间歇性地得到这样的错误?这是一个缓存问题吗?

每当我尝试加载about-us页面时,它都会完美加载,但每隔几天在我的日志中就会出现这样的错误,但它并不局限于单个页面。有时它是首页,有时是其他页面。

Started GET "/about-us" for xxx.xxx.xxx.xxx at 2014-08-16 07:54:06 +0100 
Processing by PagesController#about as */*;q=0.6 
Geokit is using the domain: mydomain.com 
[1m[35mPage Load (0.2ms)[0m SELECT `pages`.* FROM `pages` WHERE `pages`.`name` = 'About Us' LIMIT 1 
Completed 500 Internal Server Error in 2ms 

ActionView::MissingTemplate (Missing template pages/about, application/about with {:handlers=>[:erb, :builder, :arb], :formats=>["*/*;q=0.6"], :locale=>[:en, :en]}. Searched in: 
* "/var/www/myapp/releases/201408150651/app/views" 
* "/var/lib/ruby-rvm/gems/ruby-1.9.2-p320/gems/activeadmin-0.3.2/app/views" 
* "/var/lib/ruby-rvm/gems/ruby-1.9.2-p320/gems/kaminari-0.12.4/app/views" 
* "/var/lib/ruby-rvm/gems/ruby-1.9.2-p320/gems/devise-1.4.7/app/views" 
): 

这个问题是相似的:Random rails ActionView::MissingTemplate errors所以这是发生在其他人,但没有确定的答案有两种。

回答

1

因为有负荷的原因你不能阻止这个错误(比如你提到失踪缓存,未知的请求格式等)

您可以尝试限制的预定义的格式,如号码:

get '/about-us' => 'controller#about', :format => /(?:|html|json)/ 

你也可以禁止这个异常。创建一个新的文件(例如exception_handler.rb)目录配置/初始化这行添加到创建的文件:

ActionDispatch::ExceptionWrapper.rescue_responses.merge! 'ActionView::MissingTemplate' => :not_found 

希望它能帮助。

0

@ProblemSolvers是一个可能的解决方案。然而,我在application_controller.rb文件添加下面的方法,使这样的错误会呈现一个404页,而在屏幕上有错误消息未能

rescue_from ActionView::MissingTemplate, :with => :rescue_not_found 
protected 
def rescue_not_found 
    Rails.logger.warn "Redirect to 404, Error: ActionView::MissingTemplate" 
    redirect_to '/404' #or your 404 page 
end 

你可以在一个if语句包裹这段代码,这样的事情if Rails.env.production?假设env已设置,因此您的开发环境不会受到影响

相关问题