Created
March 26, 2014 09:56
-
-
Save troelskn/9779975 to your computer and use it in GitHub Desktop.
Rails preferred_layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
layout :conditionally_select_layout | |
# Like `layout`, but allows conditional overriding in app controller | |
def self.preferred_layout(value = nil) | |
@preferred_layout = value unless value.nil? | |
@preferred_layout | |
end | |
private | |
def conditionally_select_layout | |
if request.xhr? && request.params[:layout] == "false" | |
false | |
elsif devise_controller? | |
"modal" | |
else | |
self.class.preferred_layout | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment