Possible to use `shrine-imgix` with ix_image_tag (from `imgix-rails`) ?

14 views
Skip to first unread message

marckoh...@gmail.com

unread,
Apr 25, 2017, 7:53:34 PM4/25/17
to Shrine
I'm using shrine-imgix to easily generate URL with all the necessary parameters.

Occasionally I also want to use ix_image_tag from the imgix-rails gem to generate image tags. Not for the URL generation, but because it also automatically generates a srcset based on the parameters.

It requires a file path relative to the imgix source, rather than the full URL. Unfortunately it doesn't look like Shrine::Storage::Imgix provides such a method for this.

Should we add one?

Is it something that can be added to shrine-imgix or does it require a change in shrine itself too?

Janko Marohnić

unread,
Apr 26, 2017, 12:05:29 AM4/26/17
to Marc Köhlbrugge, Shrine
I think the easiest would be to use `URI::HTTP#path` on the URL, and pass that in to the ix_image_tag helper:

<%= ix_image_tag URI.path(photo.image.url) %>

This will work regardless of whether you're using Imgix prefix (in which case storage prefix shouldn't be included in the URL) or just storage prefix (in which the storage prefix should be included in the URL), because the storage generates the correct path.

Kind regards,
Janko

--
You received this message because you are subscribed to the Google Groups "Shrine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-shrine+unsubscribe@googlegroups.com.
To post to this group, send email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-shrine/b1d4e4d6-f194-4a81-a8aa-c38565a6e0ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Janko Marohnić

unread,
Apr 26, 2017, 12:06:09 AM4/26/17
to Marc Köhlbrugge, Shrine
Oops, sorry, that was meant to be

<%= ix_image_tag URI(photo.image.url).path %>
Reply all
Reply to author
Forward
0 new messages