开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜