Rails nested resources available in another context
I plan on having galleries with nested images, so images belong in a gallery. I would then like images to have a Boolean option to determine whether or not a particular image shows up on the front page. Setting up a nested resource with a Boolean property is simple, but I haven't yet figured out how to access all images that have that property set to true.
Is iterating开发者_开发技巧 through each gallery and image the only way to do that? It seems to me there must be a better way...
Create a scope on the Image class and then you can chain that scope onto any other activerecord list of images:
class Image
scope :homepage, where(:appear_on_homepage => true)
end
@gallery.images.homepage # Just the relevant images
精彩评论