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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -