Created
February 2, 2012 23:54
-
-
Save parndt/1726580 to your computer and use it in GitHub Desktop.
change theme in your helper for joshuascott
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
def current_theme | |
# first, check if we've tried to access this already and if so @current_theme will be populated with a value. | |
@current_theme ||= if params[:ChangeTheme] == "true" | |
# If the user is trying to change the theme, first: construct an array of possible themes. | |
# then: reject the theme in the current session if it is present. | |
# Finally, grab a random sample to use a random theme from the array of themes. | |
%w[power.css creative.css communication.css].reject{|theme| theme == session[:current_theme]}.sample | |
else | |
# The user is not trying to change the theme so just return the current theme saved to sesssion OR | |
# return the default theme which is 'power.css' | |
session[:current_theme] || 'power.css' | |
end | |
# Now store the result of @current_theme into the session for the next request | |
session[:current_theme] = @current_theme | |
# Finally, return the @current_theme | |
@current_theme | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment