Skip to content
spanner edited this page Sep 13, 2010 · 34 revisions

This is a fork of the multi_site extension. The main addition is a scoped finder that can be included in any model by calling is_site_scoped, but there are a few other minor changes: the site detection mechanism is shifted to ActionController so that a current_site method can be made available alongside current_user, and a couple of useful email fields have been added to the site model while I work out what to do with site ownership.

A spec is included for the new Multisite::ControllerExtension. I haven’t worked out how to spec the scoped finder yet. It looks like this:


class Forum < ActiveRecord::Base
  is_site_scoped
  ...
end

This has three main effects, all quite simple:

  • a site association is declared and validated
  • an alias_method_chain means that Forum.find(:all) is effectively the same as current_site.forums.find(:all)
  • a before_validation filter sets forum.site ||= current_site

Where current_site is a class method that returns Page.current_site, which has been set by the controller’s before_filter (which I’ve moved but not changed). If no site is found we raise a MultiSite::SiteNotFound exception.

The forum model in this example must have a site_id column, by the way.

Clone this wiki locally