rake assets:precompile attempting to connect to database

前端 未结 6 853
余生分开走
余生分开走 2020-12-14 06:24

I\'m attempting to debug why my application is attempting to connect to my database when I run rake assets:precompile --trace.

I\'m probably missing so

6条回答
  •  青春惊慌失措
    2020-12-14 07:02

    I had that same problem. After updating Sprockets to version 3, whenever I tried to precompile the assets locally (development), however using the settings of the production environment, I had this error:

    rake aborted! Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

    Because in my local (development) I use MySQL and in the server (production), I use Postgres.

    The answer marked as resolved does not work for me, because config.assets.initialize_on_precompile is not available in Rails 4.2.1.

    To solve, I followed 3 simple steps:

    1. In your Gemfile, add: gem "activerecord-nulldb-adapter"
    2. In database.yml, change the adapter as follow:

      production:
        adapter: <%= ENV['DB_ADAPTER'] ||= 'postgresql' %>
      
    3. To compile your production assets locally. run in your terminal

      DB_ADAPTER=nulldb RAILS_ENV=production rake assets:precompile
      

    This solutions solved to me and I sawyed here.

提交回复
热议问题