你如何从轨道控制器操作发出404响应?
从轨道控制器操作发出404响应的首选方式是什么?
这似乎很好…
# Rails 2 and below render :file => "#{RAILS_ROOT}/public/404.html", :status => 404 # Rails 3 and up render :file => "#{Rails.root}/public/404.html", :status => 404 你也可以
 raise ActiveRecord::RecordNotFound 
例外。
以下方法对我来说是最好的:
 raise ActionController::RoutingError.new('Not Found') 
要不就
 raise ActionController::RoutingError, 'Not Found' 
或者还有一些其他的解决scheme: 如何在Rails中redirect到404?
参考 :
 render :file => '/path/to/some/filenotfound.rhtml', status => 404, :layout => true 
在ApplicationController中定义一个方法如下:
 def render_404 render :file => "#{RAILS_ROOT}/public/404.html", :status => 404 end 
 如果你想在redirect(例如302)上发出一个状态码,你可以把它放在routes.rb : 
  get "/somewhere", to: redirect("/somewhere_else", status: 302) 。 
 但是,这只能用于redirect,而不是直接加载页面。