Rails预编译资产-无法在本地访问预编译的文件 [英] Rails precompile assets - Cannot access precompiled files locally

查看:84
本文介绍了Rails预编译资产-无法在本地访问预编译的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Rails应用程序中有一个神秘的问题,我无法解决.

I have a mysterious problem in my rails application, which I cannot fix.

问题是,我想预编译CSS和JavaScript,并在部署到服务器之前在暂存环境中本地运行服务器,以检查一切是否正常.

The thing is that I want to precompile my CSS and JavaScripts and run the server on the staging environment locally to check if everything is ok, before I deploy to the server.

我运行以下命令来预编译文件:

I run this command to precompile the files:

rake assets:precompile RAILS_ENV=staging

要在登台环境中启动服务器,请运行以下命令:

To start the server in staging environment i run this command:

rails s -e staging

文件已成功预编译并放置在public/assets文件夹中,但无法在浏览器中加载,我也无法从浏览器手动访问文件.

The files are being precompiled successfully and placed in the public/assets folder, but can not be loaded in the browser, and I cannot access the files manually from the browser either.

我的staging.rb环境文件如下:

My staging.rb environment file looks like this:

 # 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 = false
  config.static_cache_control = "public, max-age=2592000"
  config.action_controller.perform_caching = true

  # Compress JavaScripts and CSS
  config.assets.compress = true
  config.assets.debug = true

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

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

  # Use a different cache store in production
  #config.cache_store = :dalli_store, 'localhost:11211'


  # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
  config.assets.precompile += %w( .svg .eot .woff .ttf )

在使用以下版本的红宝石和铁轨时:

In using following versions of ruby and rails:

Ruby v.1.9.3 Rails v.3.2.14

Ruby v. 1.9.3 Rails v. 3.2.14

推荐答案

通过注释以下行解决了该问题:

Solved the problem by outcommenting the line:

config.serve_static_assets = false

这篇关于Rails预编译资产-无法在本地访问预编译的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆