0

I have a rails 4 app. I am uploading assets using Carrierwave and it allows me to save resized versions as well as the original. If I upload 'myimage.jpg' it will also save 'xs_myimage.jpg' to AWS S3. The problem is, the xs version name isn't stored anywhere, so I don't know how to serve that image.

This is my image call in the view:

<%=      image_tag (@portfolio.img) %>

Some how I'd like to call the xs_myimage.jp:

<%=      image_tag 'xs_'(@portfolio.img)%> #I know this doesn't work, its just what I've tried

3 Answers 3

1

Carrierwave will automatically generate an URL helper for every version of the asset you declare. Consider this:

class MyUploader < CarrierWave::Uploader::Base
  version :xs do
    # ...
  end
end

You can then use the generated helper:

uploader = MyUploader.new # or get the instance out of your model (@portfolio.img)
uploader.xs.url
1
  • Great! I had my Uploader set like that I just didn't know how to do @portfolio.img.xs.url Jan 20, 2015 at 16:04
0

In Carrierwave uploader

version :xs do
  process resize_to_limit: [50, 50]
end

then in view

<%= image_tag(@portfolio.img.xs.url) %>
0

Try to use this

<% 
  parts = @portfilio.img.split('/')
  parts[-1]="xs_#{parts.last}"
  img = parts.join('/')
%>

<%= image_tag img %>

But its very bad solution. If "xs" is a smaller(bigger) size of image why you doesn't use carrierwave thumbs?

3
  • that puts the xs in front of the whole path, like: "xs_https:/region.amazonaws.com/bucketname/my_image.jpg" Jan 20, 2015 at 15:20
  • I am uploading many different sizes, that's why I'm not using capybara. Thank you, though. Jan 20, 2015 at 16:05
  • oh, I am sorry, I mistake capybara with carrierwave :)
    – AlxGol
    Jan 20, 2015 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.