首页 文章

如何以不区分大小写的方式订购记录?

提问于
浏览
0

在我的控制器的 index 视图中,我试图按名称排序 projects

class ProjectsController < ApplicationController

  def index
    @projects = current_user.projects.order(:name)
  end

end

问题是,这给了我所有项目首先以大写字母开头(按字母顺序排列)和 then 所有以小写字母开头的项目 .

有没有办法在不更改数据库值的情况下一起订购它们?

现在我正在使用SQLite,但我可能想稍后转移到Postgres .

谢谢你的帮助 .

1 回答

  • 1

    这应该在SQLite和PostgreSQL中都有效:

    @projects = current_user.projects.order('LOWER(name)')
    

相关问题