Skip to content

Instantly share code, notes, and snippets.

@jblanche
Created November 9, 2010 17:53
Show Gist options
  • Save jblanche/669487 to your computer and use it in GitHub Desktop.
Save jblanche/669487 to your computer and use it in GitHub Desktop.
# DragonFly makes image handling with Rails3 easy but you must have one and only one image per field
# but what if I want to display a Gallery of places photos ?
# Is there a way to do something like this ? Where I could have only one image for a place and maybe ten for another one ?
class Place
include Mongoid::Document
images_accessor :place_images #Note the final S : imageS_accessor
# This I would like to avoid
# image_accessor :place_image_1
# image_accessor :place_image_2
# image_accessor :place_image_3
# image_accessor :place_image_4
# image_accessor :place_image_5
# (...)
end
# Iterate over the images and show them
<% @place.place_images.each do |place_image| %>
<%= image_tag place_image.url %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment