Made multi coop installation available as an option in app_config.yml.

This commit is contained in:
Benjamin Meichsner 2009-08-13 16:32:38 +02:00
parent f4edfacd91
commit fd97c1fc60
4 changed files with 16 additions and 9 deletions

1
MULTI_COOP_INSTALL Normal file
View file

@ -0,0 +1 @@
TODO..

View file

@ -1,8 +1,6 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
# If you wanna run multiple foodcoops on one installation uncomment next line. before_filter :select_foodcoop, :authenticate, :store_controller
#before_filter :select_foodcoop
before_filter :authenticate, :store_controller
after_filter :remove_controller after_filter :remove_controller
# sends a mail, when an error occurs # sends a mail, when an error occurs
@ -140,6 +138,7 @@ class ApplicationController < ActionController::Base
# It uses the subdomain to select the appropriate section in the config files # It uses the subdomain to select the appropriate section in the config files
# Use this method as a before filter (first filter!) in ApplicationController # Use this method as a before filter (first filter!) in ApplicationController
def select_foodcoop def select_foodcoop
if Foodsoft.config[:multi_coop_install]
# Get subdomain # Get subdomain
subdomain = request.subdomains.first subdomain = request.subdomains.first
# Set Config # Set Config
@ -147,4 +146,5 @@ class ApplicationController < ActionController::Base
# Set database-connection # Set database-connection
ActiveRecord::Base.establish_connection(Foodsoft.database(subdomain)) ActiveRecord::Base.establish_connection(Foodsoft.database(subdomain))
end end
end
end end

View file

@ -1,6 +1,10 @@
# Foodsoft configuration # Foodsoft configuration
development: &defaults development: &defaults
# If you wanna serve more than one foodcoop with one installation
# Don't forget to setup databases for each foodcoop. See also MULTI_COOP_INSTALL
multi_coop_install: false
# name of this foodcoop # name of this foodcoop
name: FC Test name: FC Test
# foodcoop contact information (used for FAX messages) # foodcoop contact information (used for FAX messages)

View file

@ -13,10 +13,12 @@ module Foodsoft
end end
def config(rails_env = @@env) def config(rails_env = @@env)
raise "No config for this environment (or subdomain) available!" if @@configs[rails_env].nil?
@@configs[rails_env].symbolize_keys @@configs[rails_env].symbolize_keys
end end
def database(rails_env = @@env) def database(rails_env = @@env)
raise "No database for this environment (or subdomain) available!" if @@databases[rails_env].nil?
@@databases[rails_env].symbolize_keys @@databases[rails_env].symbolize_keys
end end