Ruby S3 URL helper

(Arran Scott) #1

Is there a way to get the URL on the Ruby side for the files uploaded to S3?

I have a partial that I’m pulling in with ajax that loops through a load of filenames, something like the following.

filenames.each do |filename|
  <%= image_tag filename %>

The filename is an image that will show in a slideshow/carousel, these images are uploaded to S3 and I want to get the full path to each image on S3.

I’ve traced this through and have seen how this is done on the front-end in the Ember app but I specifically want to get this on the Ruby side.


(Régis Hanol) #2

How are you generating filenames?

(Arran Scott) #3

filenames is a table, belonging to User.

The filenames table stores filenames for images uploaded to a users slideshow.

I’ve managed to solve this by adding an upload_id column to my table, and when creating the upload with Upload.create_for I set the upload_id manually in the filenames table. This way I can find the upload using the Upload.find_by method and get the URL for the upload.

Seems to work ok, happy to be told if there will be an issue doing it this way.

(Régis Hanol) #4

That’s the way to go :thumbsup:

(Régis Hanol) #5