Search code examples
cssruby-on-railsformssubdomaincustomization

Rails user site customization options form to change CSS?


I'm currently working on a simple web application where users each have their own site with its own subdomain.

I want to give each user a settings panel where they have a form for changing a few simple css properties for only their site.

I'm thinking of something like a simpleform form with jquery and a colour picker to change the elements colour. Each user would probably have to have their own stylesheet though? (Not with full access to it but just so that the properties are unique to that site.)

Im not completely sure how to put that all together.

If anyone has ideas I would greatly appreciate your help.


Solution

  • Okay so the answer I found is pretty simple.

    To change the background-color I added a :string field to my sites table called bgcolor.

    I then added the new inputs to my simpleform forms - on the new and edit views for Site.

    Finally I added an inline <style> block to the layout I use for the user's Site

    <style type="text/css">
    
      body{ background-color: <%= @site.bgcolor %>;}
    
    </style>
    

    same for everything else I want to customize. And everything seems to work. Win for ERB.