我有一个名为@venues
的数组,其中包含半径范围内的所有餐馆。每个地点has_many
菜肴,我想在venue
中插入一系列这些菜肴。
@venues = Venue.within(radius, :origin => [lat, lng]).order('distance ASC')
@venues.each do |venue|
dishes = venue.dishes.where("? BETWEEN DATE(served_from) AND DATE(served_until)", Date.today)
# insert dishes into venue
end
如何将菜肴插入场地,以便我可以访问场地的所有可用菜肴:@venues[i].dishes
?
答案 0 :(得分:4)
在Dish
本身添加范围可能更有意义:
scope :today, :conditions => ["? BETWEEN DATE(served_from) AND DATE(served_until)", Date.today]
有了这个,您可以使用dishes
@venues[i].dishes.today