How to write active record for price less than or equal to and price less than or equal to by scope in ruby.
i tried like this.
scope :price, -> (price_lteq_or_price_gteq) { where("price_paisas >= ? or price_paisas <= ?", price_lteq_or_price_gteq, price_lteq_or_price_gteq)}
Controller
def index
@properties = Property.where(:status=>'1')
@properties = @properties.status(params[:status]) if params[:status].present?
@properties = @properties.price(params[:price_lteq]) if params[:price_lteq].present?
@properties = @properties.price(params[:price_gteq]) if params[:price_gteq].present?
end
when i tried like this,i got query like this
SELECT `properties`.* FROM `properties` WHERE `properties`.`status` = '1' AND (price_paisas >= '000' or price_paisas <= '000') AND (price_paisas >= '49900' or price_paisas <= '49900')
`
what i need is active record like this
SELECT `properties`.* FROM `properties` WHERE `properties`.`status` = '1' AND (price_paisas >= '000' and price_paisas <='49900')
How to do so. Please help. Any help is appreciable.
Aucun commentaire:
Enregistrer un commentaire