ruby on rails - How to search an integer field in ActiveRecord? -
i want users able search database using function:
def self.search(query) new_query = (query.to_d * 100).to_i where("price_in_cents ?", new_query) end
the problem prices
stored in database integers
, if searches "10.99" should actually search "1099".
the function above doesn't work, though, , wonder doing wrong.
thanks help.
why use "like" number comparison? should use either "=" or ">=" etc.
def self.search(query) new_query = (query.to_d * 100).to_i where("price_in_cents = ?", new_query) end
Comments
Post a Comment