“预编译资产失败";在将rails mongodb应用程序部署到heroku上

问题描述:

我正在尝试使用mongodb将rails应用程序部署到heroku,但仍会收到错误消息:

I'm trying to deploy a rails app using mongodb to heroku, but keep getting the error:

NoMethodError: undefined method `active_record' for #<Rails::Application::Configuration:0x007fb2d41e17f0>
...

Precompiling assets failed.

在询问之前,我已经尝试了所有方法,例如以下解决方案-( Heroku预编译资产失败 Ruby on Rails预编译资产失败),但我仍然可以不能让它工作

I've tried everything before asking, such as solutions from the following - (Heroku Precompiled Assets Failed, Ruby on Rails Precompiling assets failed) but I still can't get this to work

1. 创建应用程序时,我使用-O选项跳过活动记录:

1. When I created the app, I used the -O option to skip active record:

rails new app -T -O

2. 我删除了sqlite3.这是Gemfile:

2. I removed sqlite3. Here's the Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.1.8'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'spring',        group: :development

group :production do 
    gem 'mongoid', github: "mongoid/mongoid"
end

gem 'bson_ext'
gem "omniauth-twitter"
gem "figaro", "~> 0.7.0"
gem "heroku"

group :production do
  gem 'thin'
end 

3. 在application.rb中,我添加了:

3. In application.rb, I added:

config.assets.initialize_on_precompile = false

...并注释掉,需要在文件顶部添加"rails/all":

# require 'rails/all'
require "action_controller/railtie"
require "action_mailer/railtie"
# require "active_resource/railtie"
require "sprockets/railtie"

4. 在production.rb中,我注释掉了:

4. In production.rb, I commented out:

config.active_record.dump_schema_after_migration = false

5. 在mongoid.yml文件中,我添加了ENV ['MONGOHQ_URL'].这是文件:

5. In the mongoid.yml file, I added ENV['MONGOHQ_URL']. Here's the file:

development:
# Configure available database sessions. (required)
sessions:
# Defines the default session. (required)
default:
      # Defines the name of the default database that Mongoid can connect to.
  # (required).
  database: navut_development
  # Provides the hosts the default session can connect to. Must be an  array
  # of host:port pairs. (required)
  hosts:
    - localhost:27017
  options:
    # Change the default write concern. (default = { w: 1 })
    # write:
    # w: 1



    # Change the default consistency model to primary, secondary.
    # 'secondary' will send reads to secondaries, 'primary' sends everything
    # to master. (default: primary)
    # read: secondary_preferred

    # How many times Moped should attempt to retry an operation after
    # failure. (default: The number of nodes in the cluster)
    # max_retries: 20

    # The time in seconds that Moped should wait before retrying an
    # operation on failure. (default: 0.25)
    # retry_interval: 0.25

    # The connection pool size per-node.  This should match or exceed the
    # number of threads for a multi-threaded application. (default: 5)
    # pool_size: 5

    # The time in seconds that Moped should wait for the pool to provide
    # an available connection.  This number should probably remain at the 
    # default, unless for some reason you absolutely need to limit the
    # pool_size, as this wait is only used when the pool is saturated.
    # (default: 0.5)
    # pool_timeout: 0.5

    # The time in seconds before Moped will timeout connection and node
    # operations. (default: 5)
    # timeout: 5

    # The amount of time in seconds between forced refreshes of node 
    # information including the discovery of new peers. (default: 300)
    # refresh_interval: 300

    # The amount of time in seconds that a node will be flagged as down.
    # (default: 30) 
    # down_interval: 30

    # Whether connections should use SSL. (default: nil/false)
    # ssl: false

    # Whether Moped will use the existing seeds/nodes to find other peers.
    # (default: true)
    # auto_discover: true


# Configure Mongoid specific options. (optional)
options:
# Includes the root model name in json serialization. (default: false)
# include_root_in_json: false

# Include the _type field in serialization. (default: false)
# include_type_for_serialization: false

# Preload all models in development, needed when models use
# inheritance. (default: false)
# preload_models: false

# Protect id and type from mass assignment. (default: true)
# protect_sensitive_fields: true

# Raise an error when performing a #find and the document is not found.
# (default: true)
# raise_not_found_error: true

# Raise an error when defining a scope with the same name as an
# existing method. (default: false)
# scope_overwrite_exception: false

# Use Active Support's time zone in conversions. (default: true)
# use_activesupport_time_zone: true

# Ensure all times are UTC in the app side. (default: false)
# use_utc: false
test:
  sessions:
    default:
      database: navut_test
      hosts:
        - localhost:27017
      options:
        read: primary
    # In the test environment we lower the retries and retry interval to
    # low amounts for fast failures.
    max_retries: 1
    retry_interval: 0


<% if ENV['MONGOHQ_URL'] %>
  production:
    sessions:
      default:
        uri: <%= ENV['MONGOHQ_URL'] %>
        options:
          skip_version_check: true
          safe: true
<% end %>

6.在推送到heroko master之前,我输入了以下命令:

RAILS_ENV=production bundle exec rake assets:precompile
git add .
git commit -am 'precompiled assets'
git push heroku

7. 这是完整的错误:

7. Here's the full error:

git push heroku master
Counting objects: 97, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (89/89), done.
Writing objects: 100% (97/97), 23.30 KiB | 0 bytes/s, done.
Total 97 (delta 10), 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.0.0
remote: -----> Installing dependencies using 1.7.12
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 git://github.com/mongoid/mongoid.git
remote:        Installing rake 10.4.2
remote:        Installing i18n 0.7.0
remote:        Installing minitest 5.5.1
remote:        Installing thread_safe 0.3.4
remote:        Installing builder 3.2.2
remote:        Installing rack 1.5.2
remote:        Installing erubis 2.7.0
remote:        Installing mime-types 2.4.3
remote:        Installing arel 5.0.1.20140414130214
remote:        Installing bson 2.3.0
remote:        Installing coffee-script-source 1.9.0
remote:        Installing execjs 2.3.0
remote:        Installing json 1.8.2
remote:        Installing thor 0.19.1
remote:        Installing connection_pool 2.1.1
remote:        Installing hike 1.2.3
remote:        Installing multi_json 1.10.1
remote:        Installing bson_ext 1.5.1
remote:        Using bundler 1.7.12
remote:        Installing optionable 0.2.0
remote:        Installing origin 2.1.1
remote:        Installing tilt 1.4.1
remote:        Installing tzinfo 1.2.2
remote:        Installing sass 3.2.19
remote:        Installing rack-test 0.6.3
remote:        Installing coffee-script 2.3.0
remote:        Installing mail 2.6.3
remote:        Installing uglifier 2.7.0
remote:        Installing rdoc 4.2.0
remote:        Installing moped 2.0.3
remote:        Installing sprockets 2.12.3
remote:        Installing sdoc 0.4.1
remote:        Installing activesupport 4.1.8
remote:        Installing jbuilder 2.2.6
remote:        Installing actionview 4.1.8
remote:        Installing actionpack 4.1.8
remote:        Installing actionmailer 4.1.8
remote:        Installing railties 4.1.8
remote:        Installing sprockets-rails 2.2.4
remote:        Installing coffee-rails 4.0.1
remote:        Installing jquery-rails 3.1.2
remote:        Installing sass-rails 4.0.5
remote:        Installing turbolinks 2.5.3
remote:        Installing activemodel 4.1.8
remote:        Installing activerecord 4.1.8
remote:        Using mongoid 4.0.1 from git://github.com/mongoid/mongoid.git (at master)
remote:        Installing rails 4.1.8
remote:        Your bundle is complete!
remote:        Gems in the groups development and test were not installed.
remote:        It was installed into ./vendor/bundle
remote:        Post-install message from rdoc:
remote:        Depending on your version of ruby, you may need to install ruby rdoc/ri data:
remote:        <= 1.8.6 : unsupported
remote:        = 1.8.7 : gem install rdoc-data; rdoc-data --install
remote:        = 1.9.1 : gem install rdoc-data; rdoc-data --install
remote:        >= 1.9.2 : nothing to do! Yay!
remote:        Bundle completed (30.48s)
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 `active_record' for #<Rails::Application::Configuration:0x007fa06f1198a8>
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/railtie/configuration.rb:95:in `method_missing'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/config/environments/production.rb:77:in `block in <top (required)>'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/railtie.rb:210:in `instance_eval'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/railtie.rb:210:in `configure'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/config/environments/production.rb:1:in `<top (required)>'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/engine.rb:594:in `block (2 levels) in <class:Engine>'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/engine.rb:593:in `each'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/engine.rb:593:in `block in <class:Engine>'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `instance_exec'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `run'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:55:in `block in run_initializers'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:44:in `each'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:44:in `tsort_each_child'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:54:in `run_initializers'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/application.rb:300:in `initialize!'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/config/environment.rb:5:in `<top (required)>'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/application.rb:276:in `require'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/application.rb:276:in `require_environment!'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/application.rb:389:in `block in run_tasks_blocks'
remote:        /tmp/build_45864bf0c3c3fc5497da00d16a155b62/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.2.4/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 urlmaker.
remote: 

无论如何,我完全被困住了.任何帮助将非常感激. 谢谢

Anyways, I'm totally stumped. Any help would be much appreciated. Thanks

我认为您需要删除以下行: config.active_record.dump_schema_after_migration = false

I think you need to delete this line : config.active_record.dump_schema_after_migration = false

您的应用程序不会加载active_record,因此您无需对其进行配置.

Your application doesn't load active_record, so you don't need to configure it.