Adding Multiple Images using CarrierWave or Paperclip

What is the best way to create a gallery of sorts under the main Image. For example, on the Etsy tutorial where we create a product page it has one image. What If a user wanted to upload 4-5 images and display them nicely under the main image? Would we still use these gems or should we look to use something else? Thank you! Awesome Course! Keep up the great work!

Posted almost 6 years ago by johnathan
Posted almost 6 years ago by Alex Yang

Thanks for the encouragement, Johnathan!

To switch from a single image setup to multiple image functionality, the main thing we need to change is our model association. Rather than directly attach images to each Listing, we instead want to attach an album which in turn has many attached images. This is the same belongs_to/has_many association we set up in the Etsydemo course.

There are a bunch of steps that you'll need to do and it will be a little different depending on whether you're using Carrierwave or Paperclip, but here's an article that should get you most (if not all) of the way there:

Try it out and let me know if you're still having trouble.

Posted almost 6 years ago by Jeehyo Ahn

To add to that, I've realized whenever you start needing variable numbers of columns (e.g. a product may have anywhere from 0 to infinite images), it's usually a sign for a new model / redesign of your database.