Currently, I am developing a Rails website and I want to give users the option to switch between light and dark CSS themes.
In my view file, I have included the following code snippet to use a variable for the stylesheet:
<%= stylesheet_link_tag @current_stylesheet %>
I attempted to update this variable by adding a link in the view like this:
<%= link_to 'Light Theme', :action => "set_light", :id => @projects %>
This link triggers the following function in my Projects Controller:
class ProjectsController < ApplicationController
def set_light
@current_stylesheet = 'light'
end
end
However, when attempting this approach, an error stating that the template projects/set_light is missing. My goal is to change the theme stylesheet without creating new templates, simply by calling set_light and refreshing the current page. Any recommendations on how to achieve this or possibly a more effective method?