2011-07-26 3 views
1

私はRailsを初めて使用しています.2つの異なるアプリケーションレイアウトを使用することは可能でしょうか?私は自分のウェブサイトのパブリックインターフェイスを、管理者が見るものとは異なるものにしたいと考えています。したがって、すべてのパブリックアクションは1つのアプリケーションレイアウト内でレンダリングされ、すべての管理アクションは別のアプリケーションレイアウトでレンダリングされます。2つの「グローバル」/アプリケーションレイアウト

答えて

3

application_controllerのbefore_filterで使用するレイアウトを決定できます。

class ApplicationController < ActionController::Base 

    # other implementation 

    layout :determine_layout 

    def determine_layout 
    current_user.admin? ? "admin" : "application" 
    end 

end 
2
class ApplicationController < ActionController::Base 
  layout Proc.new { |controller| controller.signed_in? ? 'admin' : 'application' } 
end 
関連する問題