2014-10-03 26 views
4

我使用的ActionController ::金屬on Rails的4.1.6這樣的API控制器:ActionController :: Metal需要什麼模塊才能夠傳遞狀態代碼來呈現?

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。我在這裏丟失了什麼模塊?

回答

0

替換此:

include AbstractController::Rendering 

與此:

include ActionController::Rendering 
+0

這3個模塊,如果我取代'有一個AbstractController :: Rendering' 'ActionController :: Rendering',它會引發以下錯誤:'NoMethodError:super:no#超類方法'render'for#'。 如果我同時包含它,則呈現,但沒有狀態(原始問題)。 – Michael 2014-10-03 12:42:45

+0

奇怪。 API文檔說'ActionController :: Rendering'包含'AbstractController :: Rendering',所以不需要明確地包含兩者。我在Rails 4.0.2中重現了你的問題,我的解決方案解決了它。這可能是Rails中的一個錯誤。 – Substantial 2014-10-03 22:25:09

+1

我在Rails 4.1.6上,不確定他們是否在版本之間進行了實質性更改?也許我需要向維護人員提出問題,看看他們說了些什麼。 – Michael 2014-10-03 23:36:55

1

嘗試包括在同一順序

include AbstractController::Rendering 
include ActionView::Rendering 
include ActionController::Rendering 
相關問題