What is the best method for implementing responsive images in Rails when using asset pipeline and the image_path helper?
Doing it purely through CSS is sadly a no-go for me, since that causes issues in IE with scaling.
What is the best method for implementing responsive images in Rails when using asset pipeline and the image_path helper?
Doing it purely through CSS is sadly a no-go for me, since that causes issues in IE with scaling.
Use carrierwave
gem and upload images using versions like:
class MyUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process resize_to_fit: [800, 800]
version :thumb do
process resize_to_fill: [200,200]
end
version :large do
process resize_to_fill: [600,600]
end
end
Use different versions for different screen size.
uploader.url # => '/url/to/my_file.png' # size: 800x800
uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
uploader.large.url # => '/url/to/large_my_file.png' # size: 600x600