Skip to content

Instantly share code, notes, and snippets.

@larsar
Last active December 15, 2015 04:39
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 larsar/5203597 to your computer and use it in GitHub Desktop.
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.
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