rails – 在生产模式中找不到application.css资产

前端之家收集整理的这篇文章主要介绍了rails – 在生产模式中找不到application.css资产前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在升级应用程序以使用资产管道.

我已经将css资源编译成应用程序的css文件,但是当我以生产模式运行应用程序时,它们没有被找到

RAILS_ENV=production bundle exec rails s

我访问任何页面,我从数据库中获得正确的输出,但没有样式,日志显示

ActionController::RoutingError (No route matches [GET] 
"/assets/default.scss-1a27c...f07c.css"):

即使该文件存在于公共/资产中

$ls public/assets/def*
public/assets/default.scss-1a27c...f07c.css     public/assets/default.scss.css
public/assets/default.scss-1a27c...f07c.css.gz  public/assets/default.scss.css.gz

我需要改变什么才能让服务器找到资产文件

我的其他.css文件也是一样.他们用指纹编辑成公开/资产,但没有找到.

页面来源显示

<link href="/assets/default.scss-1a27c...f07c.css" 
media="screen" rel="stylesheet" type="text/css" />

rails(haml)源是= stylesheet_link_tag’default.scss.css’

public.assets curently包含以下文件.

$ls public/assets/def*
public/assets/default.scss-1a27c22229b7b522066181f27af4f07c.css
public/assets/default.scss-1a27c22229b7b522066181f27af4f07c.css.gz
public/assets/default.scss.css
public/assets/default.scss.css.gz

application.rb有

$cat config/application.rb 
require File.expand_path('../boot',__FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

if defined?(Bundler)
  # If you precompile assets before deploying to production,use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production,use this line
  # Bundler.require(:default,:assets,Rails.env)
end

module Linker
  class Application < Rails::Application
    config.encoding = "utf-8"
    config.filter_parameters += [:password]
    config.assets.enabled = true
    config.assets.initialize_on_precompile = false # For Heroku
    config.assets.version = '1.0'
  end
end

config / environments / production有:

$cat config/environments/production.rb 
Linker::Application.configure do
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.assets.precompile += ['default.scss.css','main.css','jquery-ui-1.8.22.custom.css']
  config.serve_static_assets = false
  config.assets.compress = true
  config.assets.compile = false
  config.assets.digest = true
  config.log_level = :debug
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
end

这似乎正在发生在所有资产,例如

Started GET "/assets/default.scss-1a27c22229b7b522066181f27af4f07c.css" for 127.0.0.1 at 2014-02-23 10:24:47 -0500
ActionController::RoutingError (No route matches [GET] "/assets/default.scss-1a27c22229b7b522066181f27af4f07c.css"):
Started GET "/assets/main-6864687b4114a1c316e444bd90f233ff.css" for 127.0.0.1 at 2014-02-23 10:24:47 -0500
ActionController::RoutingError (No route matches [GET] "/assets/main-6864687b4114a1c316e444bd90f233ff.css"):
Started GET "/assets/jquery-ui-1.8.22.custom-24319b4b1218846a3fe22a0479ae98b4.css" for 127.0.0.1 at 2014-02-23 10:24:47 -0500
ActionController::RoutingError (No route matches [GET] "/assets/jquery-ui-1.8.22.custom-24319b4b1218846a3fe22a0479ae98b4.css"):
Started GET "/assets/application-fc1d492d730f2a45581a40eac4607db8.js" for 127.0.0.1 at 2014-02-23 10:24:47 -0500
ActionController::RoutingError (No route matches [GET] "/assets/application-fc1d492d730f2a45581a40eac4607db8.js"):
Started GET "/images/link.ico" for 127.0.0.1 at 2014-02-23 10:24:48 -0500
ActionController::RoutingError (No route matches [GET] "/images/link.ico"):

解决方法

默认情况下,Rails不会在公共场合提供资产.看你的production.rb:
config.serve_static_assets = false

改变为真,你很好去. (注意:您不希望在生产中成为真实的,请记住在部署之前将其更改!)

详见Configuring Rails Applications.

原文链接:https://www.f2er.com/css/214211.html

猜你在找的CSS相关文章