Hello,
I am currently developing an engine which allows several different
sites to be served using the same code. The implementation is like
this:
- every Post has a site_id field, which is set to the ID is the site
to which the post belongs to. - in Apache config, I have something like:
ServerName site1.com
ServerAlias site2.com
site1.com and site2.com are different sites, with ID’s 1 and 2. When a
user accesses the site, engine detects which url is used (by comparing
request.host against sites database) and serves only posts with the
corresponding site_id. @current_site variable is set on application
controller level before any page is served to user.
The question:
I want to make the process of creating posts as clean as possible.
Meaning that when a post is saved, site_id is automatically attached
to it. The best possible way would be to do it in post model’s
before_save function, but the problem is that neither @current_site
variable, nor request is available to the post model.
I tried to use observers with no luck (same access problems as with
model)
Any ideas or may be some fresh approaches are very appreciated. I
really would like to leave setting site_id in controller as a last
resort (doesn’t take much time to implement, but just oh so un-
clean
TIA,
Mike.