Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !!# routes
- ActionController::Routing::Routes.draw do |map|
- # Load site routes.
- # This also loads site db configurations to ActiveRecord::Base.configurations
- Site.add_routes_to map rescue nil
- # Load Oyster routes
- map.with_options :conditions => {:host => "oyster.luckysneaks.com"} do |m|
- m.connect "/", :controller => "oyster", :action => "go_dashboard"
- m.logout "/logout", :controller => "sessions", :action => "destroy"
- m.resources :sessions, :collection => {:site => :put}
- m.resources :users
- m.resources :sites do |site|
- site.with_options :name_prefix => "site_" do |s|
- s.resources :entries, :member => {:publish => :put, :remove => :delete}, :collection => {:search => :get}
- s.resources :pages, :member => {:publish => :put, :remove => :delete}, :collection => {:search => :get}
- s.resources :comments, :member => {:moderate => :put}, :collection => {:search => :get}
- s.resources :categories, :collection => {:quick_add => :post}
- s.resources :tags
- # This route is wildly cheating at being RESTful, ie. it's not!
- s.resources :settings
- s.resources :sources
- end
- end
- end
- end
- !!# model
- class Site < ActiveRecord::Base
- def self.add_routes_to(master)
- find(:all).each do |site|
- if site.routing.blank? or !site.is_active? or !File.exists?(site.directory_for(:app))
- master.with_options :controller => "actual_sites", :conditions => {:host => site.host} do |map|
- map.connect "/inactive", :action => "inactive" if !site.is_active?
- map.connect "/*whatever", :action => "catcher"
- end
- else
- master.with_options :controller => "#{site.db_name}_content", :conditions => {:host => site.host} do |map|
- site.routing.split("\n").each do |route|
- # Caveat: Malformed routes will not get added to the map!
- begin
- map.instance_eval(route)
- rescue
- logger.info "Malformed route '#{route}' not added!"
- end
- end
- end
- end
- unless ActiveRecord::Base.configurations.has_key? site.db_name
- config = ActiveRecord::Base.configurations[RAILS_ENV]
- ActiveRecord::Base.configurations[site.db_name] = {
- :adapter => "mysql",
- :host => config["host"],
- :username => config["username"],
- :password => config["password"],
- :database => "#{site.db}"
- }
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment