Ruby rails - how to find_by multiple options?
ruby, ruby-on-rails-3
Solution
I can't test it right now, but did you try this?
Person.find_all_by_user_name_and_status(user_name, ["active", "deleted"])
if the above does not work, this should...
Person.where(:user_name => "xyz", :status => ["active", "deleted"])
# translates to:
# "select * from persons where username = 'xyz' and status in ('active', 'deleted')"
You should take a look into the Rails Guide for Active Record: http://guides.rubyonrails.org/active_record_querying.html
Problem
I want to find records based on more than one parameters. And those parameters are of mupltiple options. ``` As "SELECT something FROM mytable WHERE user_name="xyz" and status=("Active" OR "Deleted") ``` How do I translate this to rails statement? ``` Person.find_by_user_name_and_status(user_name, status) # this doesn't take the OR operator ```