开发者

Rails nested resources available in another context

开发者 https://www.devze.com 2023-04-02 23:28 出处:网络
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 pag

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

精彩评论

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