Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What module is needed with ActionController::Metal to be able to pass status code to render?

I have an Api controller using ActionController::Metal on Rails 4.1.6 like this:

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

However, if I put this in an action

render 'not_found', status: 404

It renders the 'not_found' template correctly but returns a 200 status code. Running the same render in ActionController::Base, it returns the desired 404. What module am I missing here?

like image 405
Michael Avatar asked Oct 03 '14 03:10

Michael


1 Answers

try to include these 3 modules in the same order

include AbstractController::Rendering
include ActionView::Rendering
include ActionController::Rendering
like image 173
Renat Avatar answered Oct 30 '22 02:10

Renat