Skip to content

Instantly share code, notes, and snippets.

@Kolenov
Forked from attilagyorffy/application_helper.rb
Created December 28, 2017 22:22
Show Gist options
  • Save Kolenov/0da773162f1d4380c5af9a79b85cf5af to your computer and use it in GitHub Desktop.
Save Kolenov/0da773162f1d4380c5af9a79b85cf5af 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