I’m creating a rails app and when someone searches for a property and then clicks to see more details I want to show them the property details and the images for that property. I’ve got the table figured out that contains all the property details and I’ve uploaded images to Amazon S3 but can’t work out how to construct the image url:
All properties in the database have a sysid in the main database table, for instance, 335758034, and that sysid is included in the S3 image url and the image number is appended to the end of that url so it’s possible to work out the url like so:
https://s3.amazonaws.com/images732/Photo335758034-3.jpeg
and a column in the table tells you how many images there are for a property. So if you know there’s 5 images I just have to loop through them like so:
https://s3.amazonaws.com/images732/Photo + sysid-1.jpeg
https://s3.amazonaws.com/images732/Photo + sysid-2.jpeg
https://s3.amazonaws.com/images732/Photo + sysid-3.jpeg
https://s3.amazonaws.com/images732/Photo + sysid-4.jpeg
https://s3.amazonaws.com/images732/Photo + sysid-5.jpeg
How do I do that? Any help much appreciated, thanks, Adam
UPDATE:
Here’s how it ended up:
<table summary="Property images">
<% (1..@property.image_count).each do |photo| %>
<tr>
<td><%= image_tag("https://s3.amazonaws.com/images732/Photo#{@property.sysid}-#{photo}.jpeg") %></td>
</tr>
<% end %>
In Rails,
Of course, instead of iterating through a range as in this example, you can just loop through whatever you want instead.