Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created March 26, 2014 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troelskn/9779975 to your computer and use it in GitHub Desktop.
Save troelskn/9779975 to your computer and use it in GitHub Desktop.
Rails preferred_layout
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