【发布时间】:2018-09-19 02:12:34
【问题描述】:
我想在我的 Rails 5.1 应用程序中以特定条件呈现默认的 404 页面。我的控制器里有这个
def index
...
if worker
...
else
puts "page not found"
render :status => 404
end
end
但是,即使满足条件(调用了我的 404 分支),Rails 仍会尝试渲染我的 index.htrml.erb 页面,这会导致其他错误,因为预期的模型属性不存在。有没有办法在不呈现页面的情况下返回 404 状态代码?
【问题讨论】:
-
可能正在寻找这个? stackoverflow.com/questions/2385799/…
标签: controller http-status-code-404 ruby-on-rails-5 ruby-on-rails-5.1