我有一个使用ActionController::Metal在Rails 4.1.6上的Api Controller ,如下所示:

class Api < ActionController::Metal
  include AbstractController::Rendering
  include ActionController::ImplicitRender
  include ActionController::MimeResponds
  include ActionController::RequestForgeryProtection
  include AbstractController::Callbacks
  include ActionController::HttpAuthentication::Token::ControllerMethods
  include ActionController::Head

  ...
end

但是,如果我将其付诸行动
render 'not_found', status: 404
它会正确呈现“not_found”模板,但会返回200状态代码。在ActionController::Base中运行相同的渲染,它将返回所需的404。我在这里缺少哪个模块?

最佳答案

尝试以相同的顺序包含这3个模块

include AbstractController::Rendering
include ActionView::Rendering
include ActionController::Rendering

关于ruby-on-rails - ActionController::Metal需要哪个模块才能传递状态代码以进行渲染?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26172821/

10-10 00:27