I have an array called @venues
with all the restaurants within a radius. Each venue has_many
dishes and I want to insert an array of these dishes into venue
.
我有一个名为@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
How do I insert dishes into venue so that I can access all the available dishes of an venue with: @venues[i].dishes
?
如何将菜肴插入场地,以便我可以使用@venues[I].dishes?
1 个解决方案
#1
4
It might might more sense to add a scope on Dish
itself:
在菜肴本身增加一个范围也许更有意义:
scope :today, :conditions => ["? BETWEEN DATE(served_from) AND DATE(served_until)", Date.today]
With that, you can access the available dishes
with @venues[i].dishes.today
有了它,你就可以通过@venues[i].dish .today来获取可用的菜肴了
#1
4
It might might more sense to add a scope on Dish
itself:
在菜肴本身增加一个范围也许更有意义:
scope :today, :conditions => ["? BETWEEN DATE(served_from) AND DATE(served_until)", Date.today]
With that, you can access the available dishes
with @venues[i].dishes.today
有了它,你就可以通过@venues[i].dish .today来获取可用的菜肴了