2011-12-18 27 views
1

我怎麼能創建動作控制器,它確實像一個mixin:ActionController的密新

layout Proc.new { |controller| 
    if controller.request.xhr? 
    'minimal' 
    else 
    'application' 
    end 
} 

(我不能繼承的ApplicationController,因爲我使用的寶石(設計),這是綁的ActionController 。mixin似乎更適合)

我創建了一個名爲「XHRController」的模塊,並在application.rb中使用了「ApplicationController :: Base.include XHRController」,但它在任何使用「layout」時出錯, 「before_filter」等未定義。

回答

1

所以,看起來你正在尋找決定使用哪種佈局。如果這是一個AJAX請求並且使用應用程序,那麼您希望使用'minimal'。並且您希望Devise視圖也遵循相同的決策樹。

好像你可以只是有類似:

class ApplicationController < ActionController::Base 

    layout :layout_decision_by_request_type 

    def layout_decision_by_request_type 
    if request.xhr? 
     'minimal' 
    else 
     'application' 
    end 
    end 

end 

此頁面中色器件維基也有其他兩個選項:https://github.com/plataformatec/devise/wiki/Custom-Layouts-for-Devise/22d024556aec73c8b65b630bd11a2e8ff7d17eaa

+0

感謝傑西。這是它的一部分,我也使用before_filter插入自定義標題。 – mahemoff 2011-12-19 07:09:39

相關問題