-
-
Save Kolenov/0da773162f1d4380c5af9a79b85cf5af to your computer and use it in GitHub Desktop.
Responsive Images in Rails applications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def responsive_image_tag(image, options = {}) | |
content_tag(:picture) do | |
concat content_tag(:source, nil, media: '(max-width: 768px)', srcset: image.url(:thumbnail_mobile)) | |
concat content_tag(:source, nil, media: '(max-width: 960px)', srcset: image.url(:thumbnail_tablet)) | |
concat image_tag(image.url(:thumbnail_desktop), options) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment