This repository has been archived by the owner on May 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
README
60 lines (38 loc) · 3.27 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
This gem is unmaintained, you should have a look at https://github.com/influitive/apartment instead
===================================================================================================
= Multisite for Rails Applications
This plugin provides basic support for hosting multiple sites on the same Rails code base. It is based on Matt McCray's theme_support plugin, but is essentially completely gutted and rewritten with a different focus.
The essential functionality of the plugin is to add a specific site's views to the view path. The concept of a view_path is new to Rails 2.0.
== Requirements
* This plugin is tested in Rails 2.0.2. Updates for Rails 2.1 and 2.2 (see tags) have been submitted but are untested by me.
== Differences from theme_support
If you are familiar with theme_support, a 'site' is equivalent to a 'theme' in the old system. The big difference is that this plugin doesn't make any arrangements for presenting public files. Although a public directory is created by the generator, this can just as easily be a symlink to another directory. The intended use is to configure Apache to provide access to static files for each domain, possibly with a rewrite rule falling back to the main Rails public directory. This approach was chosen because the static file caching in theme_support required long paths to static files that should be unnecessary when they are created on a per-domain basis. By letting Apache handle the specifics, static files are much simpler (no image URL coupling to the theme name, or cache expiration problems), and converting raw HTML mockups from designers tends to be much easier as well.
While theme_support only officially worked through Rails 1.1, and 1.2 with some 3rd party patches (Matt where are you?), this plugin requires Rails 2.0 for the Multiple View Path functionality (http://weblog.rubyonrails.com/2007/2/4/new-feature-for-rails-2-0-multiple-controller-view-paths). This addition to Rails makes much of the remaining complexity of the theme_support plugin disappear. One big bonus is that templates can now be created on a per-site basis without a parent template having to exist in the base directory. This is handy for creating extra content pages or breaking things down into partials.
== Usage
You can use the site_generator to create the file structure needed, or create it
yourself.
It expects the following site folder structure.
$app_root
sites/
[site_name]
views/ <- you can override application views
public/ <- intended to be the DOCUMENT_ROOT of the site
You specify which site to use in your controller by using
the declarative 'site' syntax. Although this could be automated based on domain
name, the relationship between domains and sites is not necessarily 1:1, so you will
need to develop a mechanism for choosing a 'site'.
class ApplicationController < ActionController::Base
site 'blue_bird'
...
end
You can also defer the theme lookup to a controller method:
class ApplicationController < ActionController::Base
site :get_site
def get_site
domain = Domain.find_by_name(request.domain)
domain.theme
end
...
end
Note: By setting the site in the ApplicationController you can set
the site for the whole application.