Question

I have a model Item that has an attribute :code. Items are added to the database via CSV file uploads in rails. Each :item should have a product image associated with it.

The research I've done so far seems to suggest that bulk image uploads (think 500-1000 images) are best handled outside of rails.

My question is this: if I upload bulk images to S3, is there any way to associate images to their respective :item? For simplicity, let's assume that we can easily infer :code from each images filename.

The end goal is to display an items image with something like:

<%= image_tag("#{@item.image}") %>

Let me know if I can clarify, thank you!

Was it helpful?

Solution

You gave a little to few information (e.g. what gem do you use to store the images) for an optimal answer. So here is the answer for the given question: Add the following method into your Item model:

def image
  "example_image_#{self.code}.jpg"
end

Please be aware that image_tag() will always result into an asset pipeline path. Please see http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_tag

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top