我有一个过滤器类,用于过滤转租列表。在我的过滤器类中,我有一个列表方法,它返回符合用户在表单中输入的条件的所有列表。这是过滤器类。
class Filter < ActiveRecord::Base
attr_accessible :air_conditioning, :available_rooms, :bathrooms, :furnished, :negotiable, :new, :parking, :maximum_price, :private_bathroom, :show, :term, :total_rooms, :utilities, :washer_dryer
serialize :term
def listings
@listings ||=find_listings
end
private
def find_listings
listings=Listing.order(:price)
listings=listings.where("listings.price <= ?", maximum_price) if maximum_price.present?
listings=listings.where(total_rooms: total_rooms) if total_rooms.present?
listings=listings.where(available_rooms: available_rooms) if available_rooms.present?
listings=listings.where(bathrooms: bathrooms) if bathrooms.present?
listings=listings.where(term: term)
listings=listings.where(furnished: furnished)
listings=listings.where(negotiable: negotiable)
listings=listings.where(utilities: utilities)
listings=listings.where(air_conditioning: air_conditioning)
listings=listings.where(parking: parking)
listings=listings.where(washer_dryer: washer_dryer)
listings=listings.where(private_bathroom: private_bathroom)
listings
end
end
有问题是线路
listings=listings.where(term: term)
术语保存为可以序列化的字符串。Aka ['Summer', 'Fall] 用户选中复选框以选择可用于转租的术语。但是,where 子句每次都失败。如何检查用户选择的元素是否包含在列表的条款中?