Canalización de activos de Rails 3.1: ¿por qué mis imágenes no se precompilan para la producción?

Al correr:

rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets

Everything precompiles but not my /app/assets/images/*

I even tried adding this to my environment/production.rb

config.assets.paths << "#{Rails.root}/app/assets/images"

What's wrong? thanks!

preguntado el 08 de noviembre de 11 a las 15:11

Found a solution: Add to environment/production.rb config.assets.precompile += %w[*.png *.jp?g *.gif] Why isn't this default ;ike this line says: (application.js, application.css, and all non-JS/CSS are already added) -

*.jp?g doesn't work - the ? matches exactly 1 character as it's a glob match and not a regexp. What you want is config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] -

Yup, i figured it out, thanks -

For what it's worth, I thought I was having a similar problem, but after many hours learning a lot more details on how the asset pipeline works, I discovered that I just had a syntax error in the argument passed to my image_tag helper! In Rails 3.2.8 at least, there was no need to change any of the defaults in the environment file. -

2 Respuestas

Encontré una solución: Add to environment/production.rb

config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] 

Why isn't this default ;ike this line says: (application.js, application.css, and all non-JS/CSS are already added)

respondido 27 nov., 11:16

*.jp?g doesn't work - the ? matches exactly 1 character as it's a glob match and not a regexp. What you want is config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] - Morgan Christiansson

Found this was an issue in Rails 4. When we moved our assets directory to /assets instead of /app/assets - David Rice

Why the hell we should 'precompile' images? I don't see any sense in doing this - dividir entre cero

For anyone else coming here, in Rails 5 it should be Rails.application.config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) en tu config/initializers/assets folleto - Ohhh

@divideByZero e.g. to add the md5 fingerprint, let's say you have some logo.png or default.png images, when you change them, their md5 hash will change as well, and the change in resulting URL to image will force the browser to fetch fresh copy (after change) - Januszm

Use this format for the server:

rails assets:precompile:all -e production

respondido 08 nov., 11:20

Quiere decir rake assets:precompile:all ? - Kieran Klaassen

Try `rails assets:precompile -e production' - Michael Durrant

don't need to specify environment with assets:precompile it's production by default - Jeff Dickey

A quick note: rake assets:precompile:all doesn't generate the hashed (fingerprinted) versions of my assets. For that reason, I returned to using just rake assets:precompile - Nate Cook

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.