views:

75

answers:

1

Hi Everyone,

I have been working on a Rails template recently called BaseApp2. You can see it on GitHub here: http://github.com/dannyweb/BaseApp2

There is an administrators section setup which allows the management of Users and I am working on the ability to add announcements to the public site via the admin section.

What I would really like to do, is come up with two or three alternative colour schemes for the interface and allow the administrator to choose which they prefer and select it. The chosen colour scheme would then show for all users from then on.

I have literally no idea how to go about doing this - ideally I am looking for a tutorial of some sort or something equally beginner-esque.

Thanks in advanced!

Thanks,

Danny

+4  A: 

It should be fairly easy and there are many ways to do it. You will need to save that preference somewhere. Maybe add an attribute to your user/person model that will specify that preference. And in your admin layout template, based on that preference, add an additional stylesheet. Or, add a class to the body tag and in your style sheet subclass the styles:

body {
  background-color: white;
}

body.sunshine {
  background-color: yellow;
}

The layout template:

<%= stylesheet_link_tag(current_user.theme) if current_user.theme %> 

or

<body class="<%= current_user.theme || '' %>">
tom
hope you don't mind the formatting
neutrino
I understand the adding an attribute part, and I *think* I could get my head around allowing the admin to choose from a list of options which would set a particular style id in the attribute field in the database. But...how do I set the layout to load the chosen stylesheet?
dannymcc
It could be something like: <%= stylesheet_link_tag(current_user.theme) if current_user.theme %> or <body class="<%= current_user.theme || '' %>">
tom
Hi Tom, thank you for your help! I have added <body class="<%= current_user.theme || '' %>"> to the application layout, added a migration to add a theme column to the users table. I have now completely confused myself! I have branched the work off on GitHub:http://github.com/dannyweb/BaseApp2/tree/themes. Do I need to create a theme controller?
dannymcc