开发者

image-url doesnt add a generated string to image assets in production. Rails 3.1 and Compass

开发者 https://www.devze.com 2023-04-12 09:51 出处:网络
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?

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?

I use compass version 0.12.alpha.0 And rails version 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开发者_JS百科 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

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


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:

config.assets.digest = true

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

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


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

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.

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号