2011-07-26 118 views
1

我是Rails的新手,我想知道是否可以有兩種不同的應用程序佈局?我希望我的網站的公開界面看起來與管理員看到的不同。因此,所有公共操作都將在一個應用程序佈局內呈現,而所有的管理操作都會在另一個佈局中呈現。兩個「全局」/應用程序佈局

回答

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