Hi Dmytrii
I did something similar recently, but based on domain rather than
subdomain. Either way it's easy to add a load path that's based on the
domain, so views can be overridden on a per site basis.
# In application_controller.rb
# before_filter :set_theme on controllers that need customizing based
on domain
def set_theme
theme_path = "#{Rails.root}/app/views/themes/#{current_site.name}"
self.prepend_view_path(theme_path)
end
def current_site
@current_site ||= Site.find_by_domain(current_host) ||
Site.find_by_name("main") # Site is just a wrapper class around site
settings yaml
end
def current_host
request.env["HTTP_HOST"] || request.env["SERVER_NAME"] # Fall back
on the hostname/default site
end
To override a view, for example, create a view in themes/site_name/
home/show.html.erb
Include a stylesheet based on current_site.name for custom css.
Thanks
Steve
On Sep 6, 6:14 am, Dmytrii Nagirniak <[email protected]> wrote:
> Hi,
>
> I was wondering ones do customisations per client in a Rails app?
> Clients (businesses) do not want to bother with it and usually send their
> own "layout" and stuff. So we incorporate that into the app.
>
> More information:
>
> - every client obtains a subdomain;
> - subdomain might get some of the pages customised;
> - when a client is on the main (www) subdomain, no customisation applies,
> but same functionality is available;
>
> I was thinking about overriding the lookup mechanism for the views to have
> structure like:
> views/dashboards
> index.html.erb
> views/subdomain1/index,html.erb
>
> But don't like it much as it is not very flexible (especially for assets per
> client) and will get harder and harder to maintain and test.
>
> Have you done it before?
> Any recommendations?
>
> Cheers,
> Dmytrii Nagirniakhttp://ApproachE.com<http://www.ApproachE.com>
--
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en.