I'm upgrading a Rails 3 app to 3.2 and setting up the asset pipeline. It's great for css/js but I don't really see the point in using it for images, and unfortunately I have css with a ton of references /images/*.png and the like.
Is there a way to disable the asset pipeline just for images so image_tag("x.png")
will go back to returning <img src="/images/x.png">
instead of <img src="/assets/x.png">
? Thanks!
You can monkey-patch ActionView::Base, try this in rails console:
helper.image_path "foo" #=> "/assets/foo"
module OldImagePath
def image_path(source)
asset_paths.compute_public_path(source, 'images')
end
alias_method :path_to_image, :image_path
end
ActionView::Base.send :include, OldImagePath
helper.image_path "foo" #=> "/images/foo"
You can place this in an initializer for example. By default ActionView::Base includes ActionView::Helpers::AssetTagHelper and Sprockets::Helpers::RailsHelper which both define image_path but the latter take precedence. I'm including my own module which take precedence over all of them (the code inside is taken from ActionView::Helpers::AssetTagHelper).
Although, it makes sense to use asset pipeline for images too. They get hash sum in their filenames so that they can be cached forever on the client side without asking the server whether the file was changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With