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”])