Skip to content

Instantly share code, notes, and snippets.

@thechrisoshow
Created August 16, 2011 10:43
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thechrisoshow/1148835 to your computer and use it in GitHub Desktop.
Save thechrisoshow/1148835 to your computer and use it in GitHub Desktop.
How should I white label a Rails app?
class ApplicationController < ActionController::Base
around_filter :set_white_label
private
def set_white_label
subdomains = request.subdomains - RESERVED_SUBDOMAINS
if subdomains.empty?
yield
return
end
# Obviously extract this out to work with any subdomain we want
if subdomains.first == "mycompany"
white_label_view_path = File.expand_path(File.join(RAILS_ROOT, 'app', 'white_labels', "mycompany"))
prepend_view_path(white_label_view_path)
yield
end
end
end
@thechrisoshow
Copy link
Author

What do you think of this approach?
The work happens in line #16 with prepend_view_path which will ensure a specific view path for white labelled sites. This will allow me to have different layouts/partials etc

Of course, it might be a bit hard out. I might be able to just do it all in CSS and include a special CSS file for white labelled sites.

@stueccles
Copy link

I like it. Does the prepend_view_path allow you to only override some view files or do you need to have a complete set in that directory structure?

@thechrisoshow
Copy link
Author

Only the ones you want to override. The idea is that it looks for the file in the requested path, and if it can't find it, looks in the standard dir structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment