Rails development 环境下正常的 js,到 production 下总是不生效

zhbinx · 2013年10月15日 · 最后由 Victor 回复于 2013年10月15日 · 3845 次阅读
gem 'bootstrap-sass'
gem 'select2-rails'
gem 'select2-sass-bootstrap-rails'
gem 'bootstrap-datepicker-rails'
gem 'pnotify-rails'
gem 'jquery-placeholder-rails'
//= require jquery
//= require jquery_ujs
//= require jquery.ui.datepicker
//= require jquery-placeholder
//= require bootstrap-datepicker/core
//= require bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN
//= require kindeditor
//= require wice_grid
//= require select2
//= require select2_locale_zh-CN
//= require bootstrap
//= require pnotify
//= require highcharts/highcharts
//= require highcharts/highcharts-more
//= require highcharts/highstock
//= require bootstrap-wysihtml5
//= require bootstrap-wysihtml5/locales/zh-CN
//= require_tree ../../../vendor/assets/javascripts/.
//= require_tree .

<script src="http://s1.bdstatic.com/r/www/cache/ecom/esl/1-6-6/esl.js"></script>

我用了好多好多 js

但是经常在 production 环境下部署的时候 js 不生效

每次我都会删除public\assets文件下后重新执行bundle exec rake assets:precompile

然后重启 nginx

以下是我的config\environments\production.rb,求帮助谢谢

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

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

 # Disable Rails's static asset server (Apache or nginx will already do this)
 config.serve_static_assets = true

 # Compress JavaScripts and CSS
 config.assets.compress = false

 # Don't fallback to assets pipeline if a precompiled asset is missed
 config.assets.compile = true

 # Generate digests for assets URLs
 config.assets.digest = true

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

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

看以下两个链接有没有包含你的情况,同时注意查看 log/production.log

http://ruby-china.org/topics/201 http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
config.assets.precompile += %w( home.js home.css )

rails4 中貌似遇到过类似,表示这句 bundle exec rake assets:precompile 需要加上环境变量

楼上正解

需要 登录 后方可回复, 如果你还没有账号请 注册新账号