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屋!
查看全文