Allowing users to choose custom theme in Rails
ruby-on-rails, themes
Solution
You should store the layout that the user has chosen in the session variable (easiest, but lost when the user clears cookies or uses a different computer), or in your database.
Lets say the stylesheets have five names, each corresponding to a color:
blue_stylesheet.css
green_stylesheet.css
red_stylesheet.css
orange_stylesheet.css
white_stylesheet.css
Place these files inside of `public/stylesheets.`
Store the user's choice of stylesheet into the `session[:style]` variable like so:
session[:style] = 'green'
This value will persist for as long as the user does not clear their cookies.
Create an application.erb file in your layouts if one does not already exist. The code in this file will be rendered for every template on your site. It should contain a line like `<%= yield %>`. In this file place the following:
`<%=stylesheet_link_tag session[:style]+'_stylesheet'%>`
That's it!
Good luck!
Problem
I want to give my users the ability to choose how their public page is displayed from 5 different layouts. I assume I'll need 5 different css files according to layout and then need to pass that into stylesheet_link_tag I know only how to do it using if then statements. I don't suppose that is the best way. Any help...also could it be done? Thanks