Last active
December 15, 2015 04:39
-
-
Save larsar/5203597 to your computer and use it in GitHub Desktop.
Multiple layouts based on request parameter in Rails.
Layout in URL parameter overrides cookies.
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 :resolve_layout | |
# .... | |
private | |
def resolve_layout | |
layout ||= params[:layout] | |
layout ||= cookies[:layout] | |
# Mayby overkill with case...or one might do something special for each layout | |
case layout | |
when "custom1" | |
# Do custom stuff | |
"custom1" | |
when "custom2" | |
# Do custom stuff | |
"custom2" | |
else | |
layout = "application" | |
end | |
cookies[:layout] = layout | |
layout | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment