add default db connect if fail
This commit is contained in:
@@ -13,18 +13,19 @@ class ApplicationController < ActionController::Base
|
||||
#response format must be set to JSON
|
||||
|
||||
def lookup_domain
|
||||
# if request.subdomain.present? && request.subdomain != "www"
|
||||
if request.subdomain.present? && request.subdomain != "www"
|
||||
@license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase)
|
||||
if (!@license.nil?)
|
||||
# logger.info "Location - " + @license.name
|
||||
ActiveRecord::Base.establish_connection(website_connection(@license))
|
||||
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
|
||||
else
|
||||
# reconnect_default_db
|
||||
logger.info 'License is nil'
|
||||
# redirect_to root_url(:host => request.domain) + "store_error"
|
||||
render :json => [{ status: false, message: 'Invalid Access!'}]
|
||||
render :json => [{ status: false, message: 'Invalid Access!'}]
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
def current_license(url, key)
|
||||
@@ -48,6 +49,10 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
end
|
||||
|
||||
def reconnect_default_db
|
||||
ActiveRecord::Base.establish_connection(Rails.env)
|
||||
end
|
||||
|
||||
# Regular database.yml configuration hash
|
||||
def default_connection
|
||||
@default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup
|
||||
|
||||
Reference in New Issue
Block a user