# Same site, multiple branding. Putting out the feelers

**URL:** <https://www.ruby-forum.com/t/same-site-multiple-branding-putting-out-the-feelers/120888>\
**Category:** Rails\
**Created:** [November 21, 2007, 1:50pm UTC](https://www.ruby-forum.com/t/same-site-multiple-branding-putting-out-the-feelers/120888 "2007-11-21T13:50:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![builderchad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9e8a1a/32.png) [@builderchad](https://www.ruby-forum.com/u/builderchad)\
**Post date:** [November 21, 2007, 1:50pm UTC](https://www.ruby-forum.com/t/same-site-multiple-branding-putting-out-the-feelers/120888/1 "2007-11-21T13:50:25Z")

</div>

Hi all,

Just putting out some general feelers and wondering if anyone has  
tackled this issue before in Rails.

Something along the lines of allowing different customers to run their  
own mini sites from within the main one to get all the applications and  
tools provided by that site. But with the crucial ability to choose  
their own layout and colour schemes and drag’n’drop in the services they  
want to run as well. Something like:

[http://myportal](http://myportal)… .or.  
http://…/myportal

Given the new asset stuff in Rails 2.0 which I would like to take  
advantage of as well I am wondering what kind of mechanisms are already  
in place - generally. Of course, I will eventually trawl through the  
Rails source to find out specifically but just wanted to hear from  
people who may have looked into this already.

Cheers,

Chad.

---

<div class="post-metadata">

**Author:** ![builderchad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9e8a1a/32.png) [@builderchad](https://www.ruby-forum.com/u/builderchad)\
**Post date:** [November 22, 2007, 4:46am UTC](https://www.ruby-forum.com/t/same-site-multiple-branding-putting-out-the-feelers/120888/2 "2007-11-22T04:46:20Z")

</div>

Thanks Greg, a very detailed and useful reply. I think you hit the nail  
when you said its all about clean html. The last time I did stuff like  
this was over 10 years ago using perl and the biggest problem we faced  
was the html. I guess that because we didn’t use css at the time  
because of how new and broken it was and :).

I would like the layout to be (in some cases very) different in each  
theme but also customizable by the administrator to include “modules”  
much like Mambo and that ilk.

Where I can see a challenge is when there is a radical difference  
between the skeleton of themes. For example one theme might use nested

s to display table-like data and another s. This would mean that even some or all of the smaller partials like those used to respond to ajax requests would need to be customized for each theme.

Your SitePaths class is great and really simplifies things a lot.

Thanks again for the reply,

Chad.

---

<div class="post-metadata">

**Author:** ![builderchad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9e8a1a/32.png) [@builderchad](https://www.ruby-forum.com/u/builderchad)\
**Post date:** [November 21, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/same-site-multiple-branding-putting-out-the-feelers/120888/3 "2007-11-21T19:38:42Z")

</div>

On Nov 21, 2007, at 4:50 AM, Chad T. wrote:

> Just putting out some general feelers and wondering if anyone has  
> tackled this issue before in Rails.

I’ve done it in something other than Rails, but the methodology is  
simple enough, that it doesn’t really matter if it is Rails or not.

> Something along the lines of allowing different customers to run their  
> own mini sites from within the main one to get all the applications  
> and  
> tools provided by that site. But with the crucial ability to choose  
> their own layout and colour schemes and drag’n’drop in the services  
> they  
> want to run as well. Something like:
> 
> [http://myportal](http://myportal)… .or.  
> http://…/myportal

IMO the preferred way is to use subdomains, which I described in this  
article:  
[http://www.railsdev.ws/blog/10/using-subdomains-in-rails-apps/](http://www.railsdev.ws/blog/10/using-subdomains-in-rails-apps/)

As for themes, this isn’t as hard as it sounds. First, you need to  
use really clean HTML so that CSS can take care of the vast majority  
of the work. You want each theme to be its own CSS file(s) which is  
easy to programmatically define in the page .

Depending on how radically different you want each theme, you can use  
different layouts to assemble partials in a different order etc.  
Again, the name of the layout can be declared programatically.

Between combining unique layouts and CSS files you have the majority  
of the work done. All that’s left is a file structure that makes it  
easy to add & remove themes. Another article on that same site looks  
at organizing modular site structures which would apply well to themes.

Additionally, in my apps I use a simple object called sitePaths for  
all paths within the app. Something like this:

class SitePaths

attr\_reader :layouts, :controls, :edpNavImgs, :panels, :mastheadViews, :  
mastheadImgs,  
:images, :audio, :video, :flash, :downloads

def initialize

@layouts = ‘/layouts/’  
@panels = ‘\_panels/’  
@controls = ‘/controls/’  
@mastheadViews = ‘/layouts/masthead/’  
@mastheadImgs = ‘/masthead/images/’

@images = ‘/media/images/’  
@audio = ‘/media/audio/’  
@video = ‘/media/video/’  
@flash = ‘/media/flash/’  
@downloads = ‘/media/downloads/’

end  
end

I declare an object @sitePaths in application.rb so everywhere  
there’s a need for a path, I can do something like

```
@sitePaths.controls + 'btnFormSave.gif'

```

If the site needs to support themes, I simply modify the above  
SitePaths code to allow for a theme name:

def initialize(themeName)  
@layouts = “/#{themeName}/layouts/”  
@panels = ‘\_panels/’ # not affacted by themes  
@controls = “/#{themeName}/controls/”  
@mastheadViews = “/#{themeName}/layouts/masthead/”  
@mastheadImgs = “/#{themeName}/masthead/images/”  
…  
end

The application code stays exactly the same:

```
@sitePaths.controls + 'btnFormSave.gif'

```

But now the location of that file is programmatically altered by  
pulling a theme name from an accont profile stored under the name of  
the site subdomain.

> Given the new asset stuff in Rails 2.0…

I had a very quick look at that, and it seems to be quite similar to  
the system I built into my own framework years ago to support this  
very kind of site you’re looking at. I was thinking I’d have to add  
my own layer to deal with that, so it’d be cool to see Rails have  
something built in.

Really, that’s all there is to it in terms of taking care of layout  
and appearance. As far as assembling collections of different  
functionalities per sub-site, that’s just a little more work in  
providing a UI for the user to select what they want to build a data  
structure defining a layout and the contents of each layout panel,  
and making the innards of your layouts use variables to determine  
which partial will be loaded into each panel.

– gw (www.railsdev.ws)
