Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby rails-如何通过多个选项查找_?_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby rails-如何通过多个选项查找_?

Ruby rails-如何通过多个选项查找_?,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,我想查找基于多个参数的记录。但这些参数有多种选择 As "SELECT something FROM mytable WHERE user_name="xyz" and status=("Active" OR "Deleted") 如何将此语句转换为rails语句 Person.find_by_user_name_and_status(user_name, status) # this doesn't take the OR operator 我现在无法测试,但你试过这个吗 Person.

我想查找基于多个参数的记录。但这些参数有多种选择

As "SELECT something FROM mytable WHERE user_name="xyz" and status=("Active" OR "Deleted")
如何将此语句转换为rails语句

Person.find_by_user_name_and_status(user_name, status) # this doesn't take the OR operator 

我现在无法测试,但你试过这个吗

Person.find_all_by_user_name_and_status(user_name, ["active", "deleted"])
如果上述方法不起作用,则应

Person.where(:user_name => "xyz", :status => ["active", "deleted"])
# translates to:
# "select * from persons where username = 'xyz' and status in ('active', 'deleted')"

您应该查看Rails指南中的活动记录:

谢谢!这很有效,我只是让它找到了所有,而不是找到了所有。OR运算符的措辞不正确
Person.find\u all\u by_user\u name和_status(user\u name,[“active”,“deleted”])
第二个示例不起作用:Person.where(:user\u name=>“xyz”)。where(:status=>[“active”,“deleted”])