Rails 4: assets not loading in production

前端 未结 18 1377
梦如初夏
梦如初夏 2020-11-29 15:15

I\'m trying to put my app into production and image and css asset paths aren\'t working.

Here\'s what I\'m currently doing:

  • Image assets live in /app/a
18条回答
  •  自闭症患者
    2020-11-29 16:19

    it is not recommended to let capistrano do assets precompile, because it may take ages and often time out. try to do local assets precompile.

    1st, set in config/application.rb config.assets.initialize_on_precompile = false then do local RAILS_ENV=production bin/rake assets:precompile and add those public/assets to git.

    and config/environments/development.rb, change your asset path to avoid using precompiled assets:

    config.assets.prefix = '/dev-assets'

    If you have db connection issue, means u have initializer that uses db. one way around it is to set a new environment by duplicate production.rb as maybe production2.rb, and in database.yml, add production2 environment with development db setting. then do

    RAILS_ENV=production2 bin/rake assets:precompile

    if you are still facing some issue with assets, for example ckeditor, add the js file into config/initializers/assets.rb

    Rails.application.config.assets.precompile += %w( ckeditor.js )

提交回复
热议问题