This Rails 2.3 engine will give you a system for managing multiple subdomains for a site, and the admin pages for managing them. It consists of two models, Site and Page, where pages acts as a nested set and are associated with a Site. Each page has content through a polymorphic relationship. This engine is still work in progress and not ready for use.
Pages acts as nested sets, and belong to Sites. Pages belong to polymorphic content. When viewing a page, its content will be rendered with a call to a partial by the name of the content Model in its view directory.
You need Rails 2.3! This engine is not based on the rails-engines plugin.
You need the SubdomainFu gem
The Awesome Nested Set gem from CollectiveIdea
$ script/plugin install git://github.com/angantyr/site_engine.git
For some reason, the gems don't get required correctly from within the engine, so in your environments.rb, add:
config.gem 'mbleigh-subdomain-fu', :lib => "subdomain-fu", :source => "http://gems.github.com" config.gem 'collectiveidea-awesome_nested_set', :lib => "awesome_nested_set", :source => "http://gems.github.com"
Then synchronize neccessary assets, by running this rake task, and then migrate the db:
$ rake site_engine:sync $ rake db:migrate
the site_engine:sync rake task does the following, so use it with care on an existing site:
moves the migration files over to db/migrate
moves a site_config.yml file and it's initializer into config
moves a helper over. rails doesn't seem to pick up helpers inside engines
A couple of simple steps to get up and running:
In your application_controller.rb, include the site engine module, and a before filter:
class ApplicationController < ActionController::Base include SiteEngine before_filter :site_required … end
Add the following root route:
map.root :controller => "pages"
This will use the index action on the pages controller to find the first topic for the current_site, usually “default” for the 'www' domain, and display it.
For any model, you want to display as a “page”, you need to do two things:
First, set up the polymorhic content relationship with a page:
class Topic < ActiveRecord::Base has_one :page, :as => :content end
And, then make sure that there is a partial with the model name inside its view directory:
More to come…