Skip to content

Instantly share code, notes, and snippets.

@attilagyorffy
Created June 11, 2017 14:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save attilagyorffy/2d3f5d61e23f63f72c891d4e6236327c to your computer and use it in GitHub Desktop.
Save attilagyorffy/2d3f5d61e23f63f72c891d4e6236327c to your computer and use it in GitHub Desktop.
Responsive Images in Rails applications
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