Rails 3.2.13-资产未在生产中显示

问题描述 投票:0回答:1

我花了一整天的时间来弄清楚这个问题,但没有任何积极的结果。 当我加载我的网站时,没有CSS,图像或有效的javascript。

该应用程序在Rails 3.2.13和Capistrano 2上运行。

这是我的设置:

config / environments / production.rb

Appname::Application.configure do
  config.cache_classes = true

  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  #config.serve_static_assets = false
  config.serve_static_assets = true

  config.assets.compress = true
  config.assets.compile = true
  config.assets.precompile = ['*.js', 'application.css', 'styles.css.scss', '*.css.erb']
  config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg *.woff *.ttf *.ico)

  config.assets.digest = true
  config.cache_store = :memory_store

  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
end

application.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

if defined?(Bundler)
  Bundler.require(*Rails.groups(:assets => %w(development test)))
end

module Apname
  class Application < Rails::Application
    config.encoding = "utf-8"
    config.filter_parameters += [:password]

    config.active_support.escape_html_entities_in_json = true
    config.active_record.whitelist_attributes = true

    config.assets.enabled = true

    config.assets.paths << "#{Rails.root}/app/assets/fonts"
    config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/

    config.assets.version = '1.0'
    config.assets.initialize_on_precompile = false
  end
end

我在本地运行了bundle exec rake assets:precompile >文件已生成到public/assets目录。

但仍然-生产中没有资产。

我已经不知道要在配置文件中进行哪些更改,在生产服务器上仍然是相同的结果。

每一个帮助将不胜感激!

编辑:

我只是在控制台中注意到,图像已正确加载(我可以加载http://website.com/assets/social_icons/facebook_ico.png ),而不是CSS + JS( http://IP/assets/application-3b6ba7703e465259e4e7ebee17c5ea1e.js 404未找到-.css相同)

ruby-on-rails ruby capistrano assets production
1个回答
0
投票

您在编译资产后是否尝试重新启动Web服务器?

权限设置是否正确( chmod 755 . -R )?

另外,请检查您的网络服务器配置是否指向app_root / public ,而不仅仅是app_root

编辑1:

检查您是否可以直接加载网址。 另外,验证渲染的页面是否显示正确缓存的URL。

如果两者之一失败,请尝试对生产环境进行强制编译

rake assets:precompile RAILS_ENV=production

EDIT2:如果没有任何效果,请尝试回滚到生产的默认资产配置:

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

  # 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

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

  # Version of your assets, change this if you want to expire all your assets.
  config.assets.version = '1.0'

代替:

  #config.serve_static_assets = false
  config.serve_static_assets = true

  config.assets.compress = true
  config.assets.compile = true
  config.assets.precompile = ['*.js', 'application.css', 'styles.css.scss', '*.css.erb']
  config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg *.woff *.ttf *.ico)

  config.assets.digest = true

编辑3:

编辑:

我只是在控制台中注意到图像已正确加载(我可以加载http://website.com/assets/social_icons/facebook_ico.png ),但是CSS + JS(http:// **** / assets / application -3b6ba7703e465259e4e7ebee17c5ea1e.js 404未找到-与.css相同)

这也意味着您实际上并不是在编译资产。 如果是这样,则需要使用名称后面的哈希值加载facebook_ico.png

© www.soinside.com 2019 - 2024. All rights reserved.