部署 生产状态 js 和 css 不能正常加载

jing · 2015年08月22日 · 最后由 rei 回复于 2015年09月05日 · 2958 次阅读

我已经改完 production.rb, application.rb,清理 assets,生产状态 precomplie。可是 js,css 还是没有显示出来。不知道为什么

/config/production.rb
config.cache_classes = true
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

config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
#config.serve_static_files = true
# 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 = 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

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

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

# 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
/config/application.rb
config.assets.enabled = true
 config.assets.prefix = "/assets"
 config.active_record.raise_in_transactional_callbacks = true
/initializers/assets.rb
Rails.application.config.assets.precompile += %w( jquery.flexslider.js shCore.js imagesloaded.min.js isotope.js modernizr.custom.js prettify.js toucheffects.js XRegExp.js wow.min.js font-awesome.min.css)
/app/view/application.html.erb
   <!DOCTYPE html>
<html>
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="keywords" content="">
  <meta name="description" content="">
  <link href="http://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
  <script type="text/javascript" href="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
  <script type="text/javascript" href="https://maps.gstatic.com/maps-api-v3/api/js/21/9a/intl/zh_cn/main.js"></script>

  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

  <%= csrf_meta_tags %>
</head>
<body class="home">
<%= render 'layouts/nav' %>
<div class="site-main">
  <%= yield %>
</div>
<%= render 'layouts/footer' %>
</body>
</html>

这个页面里加载一个 google 地图的 js 不知道为什么也不能用了。 Gem 里已经加了 rails_12factor,uglifier,sass-rails

本地生产过程
rake assets:clobber
 RAILS_ENV=production bundle exec rake assets:clean
rake assets:precompile RAILS_ENV=production --trace
rails server -b 0.0.0.0 -p 3000 -e production

重启了 server 还是不行。firefox debug 也没有文件找不到的错误,但是 js 效果就是没有。到底是为什么?!

1 楼 已删除

看看 public 下,是否有 assets 目录和 css 等吧。

RAILS_SERVE_STATIC_FILES=1 rails server -b 0.0.0.0 -p 3000 -e production

#2 楼 @chenge 该有的都有啊

#3 楼 @doitian ?这条命令执行完之后结果还是一样的

#5 楼 @jing 因为 rails_12factor 已经配置了这个了,所以打删除线了

bon...最后把 script 函数写在了页面里,动态就有了。==

config.serve_static_files = true #ENV['RAILS_SERVE_STATIC_FILES'].present?

去掉 turbolinks。

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