All threads / How to show a image on each property on index page

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to show a image on each property on index page

francel.webdev asked in Rails
Good evening everyone,

I am trying to create a real estate ad site and I do not know how to display the image associated with a property in each property displayed in the index page.

I have a Property model that stores the basic infos of the property. As a property may have more than one image, so I create another property_photos table, so Model PropertyPhoto with a json type names attribute to store all the photos of a property. So there is an association between the models: A Property has_many: property_photos and a PropertyPhoto belongs_to: property. I can therefore display the photos on the show page but not on the index page. I use carrierwave for photo upload.

Thank you
Not sure why wouldn't be able to loop over the images when on the index action. You should be able to loop over your PropertyPhotos there too (eg. `<%= @property.property_photos.each … %>`). 
If you give us some code you currently have, it's easier to give some more specific solution/options.
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.