I'm working on a site in Rails and I'd like for the user to be able to change the CSS stylesheet to either a light or dark theme.
I have this in my view so that I can use a variable for the stylesheet:
<%= stylesheet_link_tag @current_stylesheet %>
I tried to change that variable by having a link in my view something like this:
<%= link_to 'Light Theme', :action => "set_light", :id => @projects %>
that calls this function in my Controller:
class ProjectsController < ApplicationController
def set_light
@current_stylesheet = 'light'
end
end
Is there a way to make something like this work? Right now it says that the projects/set_light template is missing, but I don't want to make new templates, I'd just like to call set_light to change the stylesheet and refresh the current page. Any ideas on how to accomplish this, or maybe a better way to approach it?