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