Rails-4中不区分大小写的活动记录查询 [英] Case insensitive active record query in rails-4
本文介绍了Rails-4中不区分大小写的活动记录查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前,我正在Rails 4上的一个项目中工作,在example.com/username上有一个用户页面,但是如果我以适当的大小写使用用户名,它只会找到记录,如何在活动状态下执行不区分大小写的搜索记录轨道。
在下面查看我的代码
Currently I am working on a project in rails 4 in which I have a user-page at example.com/username but it only finds the record if i use username in proper case, how can I perform case insensitive search in active record rails. Check out my code below
@user = User.find_by_username(params[:username].downcase)
推荐答案
您将不得不使用类似于 where( username ILIKE?)
。 ILIKE
或类似语法取决于您的数据库。
you will have to use something similar to where("username ILIKE ?")
. the ILIKE
or similar syntax is dependant on your database though.
这篇关于Rails-4中不区分大小写的活动记录查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文