First part of multiple foodcoop installation.
This commit is contained in:
parent
3309248865
commit
1c24127928
2 changed files with 35 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
#before_filter :select_foodcoop
|
# If you wanna run multiple foodcoops on one installation uncomment next line.
|
||||||
|
before_filter :select_foodcoop
|
||||||
before_filter :authenticate, :store_controller
|
before_filter :authenticate, :store_controller
|
||||||
after_filter :remove_controller
|
after_filter :remove_controller
|
||||||
|
|
||||||
|
@ -150,4 +151,16 @@ class ApplicationController < ActionController::Base
|
||||||
def find_supplier
|
def find_supplier
|
||||||
@supplier = Supplier.find(params[:supplier_id]) if params[:supplier_id]
|
@supplier = Supplier.find(params[:supplier_id]) if params[:supplier_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set config and database connection for each request
|
||||||
|
# It uses the subdomain to select the appropriate section in the config files
|
||||||
|
# Use this method as a before filter (first filter!) in ApplicationController
|
||||||
|
def select_foodcoop
|
||||||
|
# Get subdomain
|
||||||
|
subdomain = request.subdomains.first
|
||||||
|
# Set Config
|
||||||
|
Foodsoft.set_env subdomain
|
||||||
|
# Set database-connection
|
||||||
|
ActiveRecord::Base.establish_connection(Foodsoft.database(subdomain))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,26 @@
|
||||||
raw_config = File.read(RAILS_ROOT + "/config/app_config.yml")
|
raw_config = File.read(RAILS_ROOT + "/config/app_config.yml")
|
||||||
APP_CONFIG = YAML.load(raw_config)[RAILS_ENV].symbolize_keys
|
APP_CONFIG = YAML.load(raw_config)[RAILS_ENV].symbolize_keys
|
||||||
|
|
||||||
|
module Foodsoft
|
||||||
|
@@configs = YAML.load(File.read(RAILS_ROOT + "/config/app_config.yml"))
|
||||||
|
@@databases = YAML.load(File.read(RAILS_ROOT + "/config/database.yml"))
|
||||||
|
@@env = RAILS_ENV
|
||||||
|
|
||||||
|
def set_env(env)
|
||||||
|
@@env = env
|
||||||
|
end
|
||||||
|
|
||||||
|
def config(rails_env = @@env)
|
||||||
|
@@configs[rails_env].symbolize_keys
|
||||||
|
end
|
||||||
|
|
||||||
|
def database(rails_env = @@env)
|
||||||
|
@@databases[rails_env].symbolize_keys
|
||||||
|
end
|
||||||
|
|
||||||
|
extend self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# Configuration of the exception_notification plugin
|
# Configuration of the exception_notification plugin
|
||||||
# Mailadresses are set in config/foodsoft.yaml
|
# Mailadresses are set in config/foodsoft.yaml
|
||||||
|
|
Loading…
Reference in a new issue