image-url不向生产中的映像资产添加生成的字符串。Rails 3.1和指南针

时间:2022-09-03 21:21:46

In my sass files I use image-url('image.png') to add my images but in production they arent working. It should add a string to my images but it isnt doing it. Somebody has a clue how I can fix this?

在我的sass文件中,我使用image-url('image.png')来添加我的图像,但是在生产中它们不能工作。它应该给我的图像添加一个字符串,但它没有这么做。有人知道我怎么解决这个问题吗?

I use compass version 0.12.alpha.0 And rails version 3.1.0

我用的是指南针版本0.12。0和rails 3.1.0版本

Bundle

Using rake (0.9.2) 
Using multi_json (1.0.3) 
Using activesupport (3.1.0) 
Using bcrypt-ruby (3.0.1) 
Using builder (3.0.0) 
Using i18n (0.6.0) 
Using activemodel (3.1.0) 
Using erubis (2.7.0) 
Using rack (1.3.4) 
Using rack-cache (1.0.3) 
Using rack-mount (0.8.3) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.0.2) 
Using actionpack (3.1.0) 
Using mime-types (1.16) 
Using polyglot (0.3.2) 
Using treetop (1.4.10) 
Using mail (2.3.0) 
Using actionmailer (3.1.0) 
Using arel (2.2.1) 
Using tzinfo (0.3.29) 
Using activerecord (3.1.0) 
Using activeresource (3.1.0) 
Using airbrake (3.0.4) 
Using ansi (1.3.0) 
Using archive-tar-minitar (0.5.2) 
Using bundler (1.0.18) 
Using highline (1.6.2) 
Using net-ssh (2.2.1) 
Using net-scp (1.0.4) 
Using net-sftp (2.0.5) 
Using net-ssh-gateway (1.1.0) 
Using capistrano (2.9.0) 
Using chunky_png (1.2.5) 
Using coffee-script-source (1.1.2) 
Using execjs (1.2.9) 
Using coffee-script (2.2.0) 
Using columnize (0.3.4) 
Using fssm (0.2.7) 
Using sass (3.1.10) 
Using compass (0.12.alpha.0) 
Using compass-960-plugin (0.10.4) 
Using rest-client (1.6.7) 
Using couchrest (1.1.2) 
Using couchrest_model (1.1.2) 
Using daemons (1.0.10) 
Using diff-lcs (1.1.3) 
Using factory_girl (2.0.2) 
Using rack-ssl (1.3.2) 
Using json (1.6.1) 
Using rdoc (3.10) 
Using thor (0.14.6) 
Using railties (3.1.0) 
Using factory_girl_rails (1.1.0) 
Using rails (3.1.0) 
Using formtastic (2.0.0.rc5) 
Using gem_plugin (0.2.3) 
Using geokit (1.6.0) 
Using gravatar (1.0) 
Using haml (3.1.3) 
Using haml-rails (0.3.4) 
Using jquery-rails (1.0.14) 
Using libv8 (3.3.10.2) 
Using ruby_core_source (0.1.5) 
Using linecache19 (0.5.12) 
Using metaclass (0.0.1) 
Using mocha (0.10.0) 
Using money (3.1.5) 
Using mongrel (1.2.0.pre2) 
Using nifty-generators (0.4.6) 
Using rspec-core (2.6.4) 
Using rspec-expectations (2.6.0) 
Using rspec-mocks (2.6.0) 
Using rspec (2.6.0) 
Using rspec-rails (2.6.1) 
Using ruby-debug-base19 (0.11.25) 
Using ruby-debug19 (0.11.6) 
Using sass-rails (3.1.4) 
Using state_machine (1.0.2) 
Using therubyracer (0.9.4) 
Using turn (0.8.2) 
Using uglifier (1.0.3)

production.rb

production.rb

MyApp::Application.configure do

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

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

  # Specify the default JavaScript compressor
  config.assets.js_compressor  = :uglifier

  # Specifies the header that your server uses for sending files
  # (comment out if your front-end server doesn't support this)
  config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx

  config.generators.stylesheet_engine = :sass
end

2 个解决方案

#1


3  

Ok i finally found the answer. I thought the issue was compass but it wasnt true. This up is upgraded from a Rails 3.0 version so without asset pipeline. I simply forgot to add in production.rb:

我终于找到答案了。我原以为这是罗盘条,但事实并非如此。这是从Rails 3.0版本升级的,所以没有资产管道。我只是忘了加生产。

config.assets.digest = true

As the assets are compiled with rake assets:precompile I didnt had this problem in development.

由于这些资产是用rake资产编译的:precompile我在开发过程中没有遇到这个问题。

Right now it is possible to use image-url or image-path in the sass files.

现在可以在sass文件中使用image-url或image-path。

#2


0  

This is an issue with assets pipeline capabilities provided by Sprocket in rails 3.1. You can chain parsers to fix that in production like so

这是由rails 3.1中的Sprocket提供的资产管道功能的问题。您可以像这样在生产中对解析器进行链式修复

stylesheet.css.sass.erb

What that does is begin parsing as erb (or .haml for haml, whatever), then sass, css is just not needed but I believe it's there by default.

它所做的是开始解析为erb(或。haml,等等),然后sass, css是不需要的,但我相信它是默认存在的。

You need to change

您需要更改

image-url('image.png')

to

image-url(<%= asset_path "image.png" %>)

Heres a blog post explaining it http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/

这里有一篇博客解释了这一点:http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in the real-world/

#1


3  

Ok i finally found the answer. I thought the issue was compass but it wasnt true. This up is upgraded from a Rails 3.0 version so without asset pipeline. I simply forgot to add in production.rb:

我终于找到答案了。我原以为这是罗盘条,但事实并非如此。这是从Rails 3.0版本升级的,所以没有资产管道。我只是忘了加生产。

config.assets.digest = true

As the assets are compiled with rake assets:precompile I didnt had this problem in development.

由于这些资产是用rake资产编译的:precompile我在开发过程中没有遇到这个问题。

Right now it is possible to use image-url or image-path in the sass files.

现在可以在sass文件中使用image-url或image-path。

#2


0  

This is an issue with assets pipeline capabilities provided by Sprocket in rails 3.1. You can chain parsers to fix that in production like so

这是由rails 3.1中的Sprocket提供的资产管道功能的问题。您可以像这样在生产中对解析器进行链式修复

stylesheet.css.sass.erb

What that does is begin parsing as erb (or .haml for haml, whatever), then sass, css is just not needed but I believe it's there by default.

它所做的是开始解析为erb(或。haml,等等),然后sass, css是不需要的,但我相信它是默认存在的。

You need to change

您需要更改

image-url('image.png')

to

image-url(<%= asset_path "image.png" %>)

Heres a blog post explaining it http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/

这里有一篇博客解释了这一点:http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in the real-world/