Depends on how much you want the user to be able to customize. Do you just want them to be able to select colors for an existing framework, or do you want them to be able to upload their own complete custom stylesheet?
For security, if you're letting users add their own custom stylesheet, the css should get sanitized so a user can't run malicious code (see this answer for example).
If you just want users to be able to customize an existing theme, you could do something like User has_one :style where
class StylesController < ApplicationController
def create
@style = current_user.build_style(style_params)
if @style.save
flash[:success] = "Style saved!"
end
end
def show
@style = Style.find(params[:id])
respond_to do |format|
format.html
format.css
end
end
private
def style_params
params.require(:style).permit(:name, :font1, :color1, :color2, :color3, :color4, :fontsize)
end
Plus a form to edit the attributes you want users to be able to customize, a show.css.erb with something like
.text-primary {
color: <%= @style.color1 %>;
}
and load the stylesheet on the user's page with a helper like
def user_style(user)
if user.style.present?
content_for :stylesheet_includes do
stylesheet_link_tag user.style.path, media: 'all', 'data-turbolinks-track' => "reload"
end
end
end
and <%= yield :stylesheet_includes %>
in the header of your application.html.erb. 'data-turbolinks-track' => "reload"
is necessary to keep turbolinks from persisting one user's custom stylesheet across other user's domains.