0
我想寫快速範圍來過濾我的餐館。過濾器的最佳範圍
我做這樣的事情
@restaurants = Restaurant.all
@restaurants = filter(@restaurants)
def filter(restaurants)
restaurants = restaurants.filter('types', params[:type].split(',')) unless params[:type].nil?
restaurants = restaurants.filter('cuisines', params[:cuisine].split(',')) unless params[:cuisine].nil?
restaurants = restaurants.filter('facilities', params[:facility].split(',')) unless params[:facility].nil?
restaurants = restaurants.filter('services', params[:service].split(',')) unless params[:service].nil?
restaurants = restaurants.filter('prices', params[:price].split(',')) unless params[:price].nil?
return restaurants
end
,其中過濾器是:
scope :filter, lambda{|type_name, type_id| includes(type_name.to_sym).where(["#{type_name}.id in (?)", type_id]) }
所以......當我得到網址:
.../search?service=1,2,3
我得到的服務1或飯店2或3,但我想要獲得服務1和2和3的餐館。 我該如何做到這一點噸,因爲它可能是?
有delete_at(沒有操作delete_at爲字符串/服務/ 1,2,3)的問題等:( – 2011-12-19 18:43:30
D'oh!在Rails 2中,我認爲它作爲一個數組通過嘗試分裂獲得一個數組的路徑組件。 – jxpx777 2011-12-20 14:31:37