Skip to content

Instantly share code, notes, and snippets.

@phurni
Created May 16, 2014 21:22
Show Gist options
  • Select an option

  • Save phurni/caac3efcbb43a38b8946 to your computer and use it in GitHub Desktop.

Select an option

Save phurni/caac3efcbb43a38b8946 to your computer and use it in GitHub Desktop.

Revisions

  1. phurni created this gist May 16, 2014.
    35 changes: 35 additions & 0 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    require File.expand_path('../boot', __FILE__)

    require 'rails/all'

    if ar_initdb = ActiveRecord::Railtie.initializers.find {|item| item.name == 'active_record.initialize_database'}
    ActiveRecord::Railtie.initializers.delete(ar_initdb)

    ActiveRecord::Railtie.initializer :after => ar_initdb.after do
    ActiveSupport.on_load(:active_record) do
    self.configurations = Rails.application.config.database_configuration

    begin
    establish_connection
    rescue ActiveRecord::NoDatabaseError, ActiveRecord::AdapterNotSpecified, ActiveRecord::AdapterNotFound
    if app.config.database_not_required
    app.config.middleware.delete "ActiveRecord::QueryCache"
    app.config.middleware.delete "ActiveRecord::ConnectionAdapters::ConnectionManagement"
    else
    warn <<-end_warning
    Oops - You have a database configured, but it doesn't exist yet!
    Here's how to get started:
    1. Configure your database in config/database.yml.
    2. Run `bin/rake db:create` to create the database.
    3. Run `bin/rake db:setup` to load your database schema.
    end_warning
    raise
    end
    end
    end
    end
    end

    # Rest of your application.rb file