2011-10-11 17 views
3

在我的sass文件中,我使用image-url('image.png')添加了我的图像,但是在生产中它们不起作用。它应该添加一个字符串到我的图像,但它没有这样做。有人有线索我怎么能解决这个问题?image-url不会将生成的字符串添加到生产中的图像资源中。 Rails 3.1和Compass

我用指南针版本0.12.alpha.0 和Rails 3.1.0版本

捆绑

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

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 

回答

3

好吧,我终于找到了答案。我认为这个问题是指南针,但并非如此。这是从一个Rails 3.0版本升级,所以没有资产管道。我只是忘了在production.rb补充:

config.assets.digest = true 

由于资产与rake assets:precompile编译我没有在发展中这个问题。

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

+0

好找! +1 :) – Tilo

0

这与资产管道能力的问题由Sprocket在rails 3.1中提供。你可以链解析器来解决,在生产像这样

stylesheet.css.sass.erb 

什么,做的仅仅是开始解析为ERB(或.haml为HAML,等等),然后SASS,CSS是不必要的,但我相信这将是有默认。

您需要更改

image-url('image.png') 

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

继承人一篇博客文章中解释它http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/

+0

你确定没有其他办法吗?我认为image-url必须做同样的事,因为gem sass-rails –

+0

https://github.com/rails/sass-rails在这里他们说你可以使用image-url,但我认为image-url是某处用指南针或其他东西覆盖...... –

+0

感谢您的帮助。我发现自己是答案。 asset_path不会工作,因为我在production.rb中缺少配置变量。愚蠢的错误:) –

相关问题