diff --git a/app/models/user.rb b/app/models/user.rb index 55e6ea9..4bce879 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,7 @@ class User < ActiveRecord::Base + establish_connection :local_development + enum user_type: { institutional: 0, vima: 1, okeanos: 2, admin: 3 } validates :username, :user_type, presence: true end diff --git a/config/application.rb b/config/application.rb index 788b831..1546a1e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,40 +1,48 @@ require File.expand_path('../boot', __FILE__) require 'rails/all' # Production doesn't use bundler # you've limited to :test, :development, or :production. if ENV['RAILS_ENV'] != 'production' Bundler.require(*Rails.groups) else # Dependencies to load before starting rails in production require 'jquery-rails' end -module Base +module Baas + def self.settings opts = nil + @settings ||= {} + + return @settings if opts.nil? + @settings.merge! opts + @settings + end + class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Store/Read localtime from the database config.active_record.default_timezone = :local # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de config.autoload_paths << Rails.root.join('lib') - config.x = {} +# config.x = {} end - def self.settings - Application.config.x - end +# def self.settings +# Application.config.x +# end def self.bean @bean ||= Bean::Client.new( YAML.load_file(Rails.root.join('config', 'beanstalk.yml'))[Rails.env].symbolize_keys[:host] ) end end diff --git a/config/initializers/00_settings.rb b/config/initializers/00_settings.rb index e69de29..1c45762 100644 --- a/config/initializers/00_settings.rb +++ b/config/initializers/00_settings.rb @@ -0,0 +1 @@ +Baas.settings local_db: "local_#{Rails.env}".to_sym diff --git a/db/migrate/20151020192733_create_users_table.rb b/db/migrate/20151020192733_create_users_table.rb index 76c0470..e371269 100644 --- a/db/migrate/20151020192733_create_users_table.rb +++ b/db/migrate/20151020192733_create_users_table.rb @@ -1,11 +1,15 @@ class CreateUsersTable < ActiveRecord::Migration + def connection + ActiveRecord::Base.establish_connection(Baas::settings[:local_db]).connection + end + def change create_table :users do |t| t.string :username, null: false t.string :email t.integer :user_type, limit: 1, null: false t.boolean :enabled, default: false t.timestamps end end end diff --git a/lib/local_db.rb b/lib/local_db.rb index 9036d8f..d3ca9a2 100644 --- a/lib/local_db.rb +++ b/lib/local_db.rb @@ -1,3 +1,3 @@ module LocalDb - establish_connection "local_#{Rails.application.class.parent_name.downcase}_#{Rails.env}".to_sym + establish_connection "local_#{Rails.env}".to_sym end