Created
June 11, 2017 14:31
-
-
Save attilagyorffy/2d3f5d61e23f63f72c891d4e6236327c 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