Ruby rails - how to find multiple options?

I want to find entries based on more than parameters. But these parameters have mupltiple parameters.

As "SELECT something FROM mytable WHERE user_name="xyz" and status=("Active" OR "Deleted") 

How to translate this to rails instruction?

 Person.find_by_user_name_and_status(user_name, status) # this doesn't take the OR operator 
+7
source share
1 answer

I can’t check it right now, but have you tried it?

 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 at the Rails Guide for Active Writing: http://guides.rubyonrails.org/active_record_querying.html

+9
source

All Articles