在为postgresql添加新gems并安装bundle

时间:2016-01-17 01:28:07

标签: ruby-on-rails postgresql heroku config

当尝试推送到heroku master时,在安装了postgresql所需的gem之后,因为heroku无法识别sqlite3,它无法预编译资产并编译应用程序。我按照此在线指南将其部署到heroku:http://jgtr.github.io/blog/2013/07/28/deploying-a-sqlite3-database-to-heroku-for-production-using-postgres/

任何想法是什么问题?

git push heroku master
Counting objects: 2287, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1951/1951), done.
Writing objects: 100% (2287/2287), 17.77 MiB | 17.00 KiB/s, done.
Total 2287 (delta 534), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.1
remote: -----> Installing dependencies using bundler 1.9.7
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Fetching gem metadata from https://rubygems.org/.........
remote:        Fetching version metadata from https://rubygems.org/...
remote:        Fetching dependency metadata from https://rubygems.org/..
remote:        Using rake 10.4.2
remote:        Installing minitest 5.8.3
remote:        Installing i18n 0.7.0
remote:        Installing thread_safe 0.3.5
remote:        Installing builder 3.2.2
remote:        Installing mini_portile2 2.0.0
remote:        Installing erubis 2.7.0
remote:        Installing rack 1.6.4
remote:        Installing mime-types 2.99
remote:        Installing json 1.8.3
remote:        Installing arel 6.0.3
remote:        Installing addressable 2.3.8
remote:        Installing execjs 2.6.0
remote:        Installing thor 0.19.1
remote:        Installing sass 3.4.19
remote:        Installing coffee-script-source 1.10.0
remote:        Installing multipart-post 2.0.0
remote:        Installing concurrent-ruby 1.0.0
remote:        Installing hashie 3.4.3
remote:        Installing high_voltage 2.4.0
remote:        Installing multi_json 1.11.2
remote:        Installing jwt 1.5.2
remote:        Using bundler 1.9.7
remote:        Installing multi_xml 0.5.5
remote:        Installing tilt 2.0.1
remote:        Installing tzinfo 1.2.2
remote:        Installing rack-test 0.6.3
remote:        Installing mail 2.6.3
remote:        Installing autoprefixer-rails 6.1.2
remote:        Installing uglifier 2.7.2
remote:        Installing select2-rails 4.0.0
remote:        Installing coffee-script 2.4.1
remote:        Installing faraday 0.9.2
remote:        Installing sprockets 3.5.0
remote:        Installing omniauth 1.2.2
remote:        Installing activesupport 4.2.1
remote:        Installing bootstrap-sass 3.3.6
remote:        Installing koala 2.2.0
remote:        Installing oauth2 1.0.0
remote:        Installing pg 0.18.4
remote:        Installing rails-deprecated_sanitizer 1.0.3
remote:        Installing globalid 0.3.6
remote:        Installing activemodel 4.2.1
remote:        Installing jbuilder 2.3.2
remote:        Installing omniauth-oauth2 1.4.0
remote:        Installing activejob 4.2.1
remote:        Installing activerecord-postgresql-adapter 0.0.1
remote:        Installing omniauth-facebook 3.0.0
remote:        Installing activerecord 4.2.1
remote:        Installing nokogiri 1.6.7
remote:        Installing loofah 2.0.3
remote:        Installing rails-dom-testing 1.0.7
remote:        Installing rails-html-sanitizer 1.0.2
remote:        Installing actionview 4.2.1
remote:        Installing actionpack 4.2.1
remote:        Installing sprockets-rails 2.3.3
remote:        Installing actionmailer 4.2.1
remote:        Installing railties 4.2.1
remote:        Installing bootstrap-datepicker-rails 1.5.0
remote:        Installing simple_form 3.2.0
remote:        Installing bootstrap-generators 3.3.4
remote:        Installing bootstrap-typeahead-rails 0.10.5.1
remote:        Installing chart-js-rails 0.0.9
remote:        Installing coffee-rails 4.1.0
remote:        Installing jquery-rails 4.0.5
remote:        Installing rails 4.2.1
remote:        Installing sass-rails 5.0.4
remote:        Bundle complete! 27 Gemfile dependencies, 67 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (26.34s)
remote:        Cleaning up the bundler cache.
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        NoMethodError: undefined method `configure' for main:Object
remote:        /tmp/build_1a115f32b847c2bee80ca9efb3688741/config/environment.rb:7:in `<top (required)>'
remote:        /tmp/build_1a115f32b847c2bee80ca9efb3688741/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:328:in `require'
remote:        /tmp/build_1a115f32b847c2bee80ca9efb3688741/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:328:in `require_environment!'
remote:        /tmp/build_1a115f32b847c2bee80ca9efb3688741/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:457:in `block in run_tasks_blocks'
remote:        /tmp/build_1a115f32b847c2bee80ca9efb3688741/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
remote:        Tasks: TOP => environment
remote:        (See full trace by running task with --trace)
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote: 
remote:  !     Push rejected, failed to compile Ruby app
remote: 
remote: Verifying deploy....
remote: 
remote: !   Push rejected to nokorupsi.
remote: 
To https://git.heroku.com/nokorupsi.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/nokorupsi.git'

这是Gemfile(我之前已经通过bundle install更新了Gemfile.lock,所以所有的gem都应该安装好了):

source 'https://rubygems.org'
ruby '2.2.1'
gem 'rails', '4.2.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'

group :development, :test do
  gem 'byebug'
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

gem 'bootstrap-sass'
gem 'high_voltage'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'simple_form'

group :development do
  gem 'better_errors'
  gem 'hub', :require=>nil
  gem 'quiet_assets'
  gem 'rails_layout'
  gem 'sqlite3'
end

group :production do
    gem 'pg'
    gem "activerecord-postgresql-adapter"
end

gem 'koala'
gem 'bootstrap-generators', '~> 3.3.4'
gem "select2-rails"
gem 'bootstrap-typeahead-rails'
gem 'bootstrap-datepicker-rails'
gem 'chart-js-rails'

这是config目录中的database.yml:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'

# default: &default
#   adapter: sqlite3
#   pool: 5
#   timeout: 5000

development:
  adapter: sqlite3
  database: database.db
  # <<: *default
  # database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: database.db
  # <<: *default
  # database: db/test.sqlite3

production:
  adapter: postgresql
  database: nokorupsi
  username: username
  password: password
  host: localhost
  # <<: *default
  # database: db/production.sqlite3

这是config目录中的application.rb:

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module MerdekaHack
  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.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # 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

    # Do not swallow errors in after_commit/after_rollback callbacks.
    config.active_record.raise_in_transactional_callbacks = true

  end
end

这是config目录中的environment.rb:

# Load the Rails application.
require File.expand_path('../application', __FILE__)

# Initialize the Rails application.
Rails.application.initialize!

这是config目录中的environment文件夹中的development.rb:

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
  # yet still be able to expire them through the digest params.
  config.assets.digest = true

  # Adds additional error checking when serving assets at runtime.
  # Checks for improperly declared sprockets dependencies.
  # Raises helpful error messages.
  config.assets.raise_runtime_errors = true

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true

  # Database for development
  set :database, "sqlite3:///database.db"


end

这是config目录中相同环境文件夹中的production.rb:

Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.

  # Code is not reloaded between requests.
  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Enable Rack::Cache to put a simple HTTP cache in front of your application
  # Add `rack-cache` to your Gemfile before enabling this.
  # For large-scale production use, consider using a caching reverse proxy like
  # NGINX, varnish or squid.
  # config.action_dispatch.rack_cache = true

  # Disable serving static files from the `/public` folder by default since
  # Apache or NGINX already handles this.
  config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
  # yet still be able to expire them through the digest params.
  config.assets.digest = true

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Use the lowest log level to ensure availability of diagnostic information
  # when problems arise.
  config.log_level = :debug

  # Prepend all log lines with the following tags.
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups.
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false

  # Connecting to postgresql
  db = URI.parse(ENV['postgres://iqwljiwwoqdysd:qzGRGgasKi_sMysSP4dcabR8Km@ec2-54-83-61-45.compute-1.amazonaws.com:5432/dde6roet07bko1'] || 'postgres://localhost/mydb')

  ActiveRecord::Base.establish_connection(
    :adapter  => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
    :host     => db.host,
    :username => db.user,
    :password => db.password,
    :database => db.path[1..-1],
    :encoding => 'utf8'
  )


end

1 个答案:

答案 0 :(得分:1)

删除:     gem“activerecord-postgresql-adapter” 从生产中再试一次。