如何避免来自rails query的此类符号@new_record
,false
,@readonly
我的哈希结果显示为
[#<Hotel id: 42, hotel_name: "Vijay: Resort De Alturas,Candolim", stars: "4", location: "North Goa", created_at: "2013-09-21 20:05:25", updated_at: "2013-09-21 20:05:25", searchable: true>, :@readonly, false]
并且当相同的查询再次触发时,它第一次工作正常,但从第二次获得不同类型的符号,如@new_record
,false
,@readonly
我的查询是
@hotels = Hotel.sort_hotel_by_price(session["search"],price_type)
def self.sort_hotel_by_price(hotels,price_sort_type=nil)
pkg_prices_in_sort_order=[]
# hotels.reject!{|h| h.to_s.chr=="@" or h==false}
pkg_prices_in_sort_order << (hotels.map{|hotel| hotel.package_prices.order("price ASC").first})
pkg_prices_in_sort_order.flatten!
pkg_prices_in_sort_order.reject!{|pkg_price| pkg_price.nil?}
pkg_prices_in_sort_order = pkg_prices_in_sort_order.sort{|x,y| x["price"]<=>y["price"]}
if (price_sort_type=="high")
pkg_prices_in_sort_order.reverse!
end
sort_hotels=[]
sort_hotels << (pkg_prices_in_sort_order.map{|s| s.hotel})
sort_hotels.flatten!
end