Is it possible to have variable find conditions for both the key and value?

Posted by DarrenD on Stack Overflow See other posts from Stack Overflow or by DarrenD
Published on 2010-04-21T15:45:24Z Indexed on 2010/04/21 18:03 UTC
Read the original article Hit count: 142

Filed under:

I'm trying to pass in both the field and the value in a find call:

@employee = Employee.find(:all,
              :conditions => [ '? = ?', params[:key], params[:value].to_i)

The output is

SELECT * FROM `employees` WHERE ('is_manager' = 1)

Which returns no results, however when I try this directly in mysqsl using the same call without the '' around is_manager, it works fine. How do I convert my params[:key] value to a symbol so that the resulting SQL call looks like:

SELECT * FROM `employees` WHERE (is_manager = 1)

Thanks, D

© Stack Overflow or respective owner

Related posts about ruby-on-rails