Ruby on rails 为什么可以';我不能从数据库中提取有序数据吗?
我似乎无法从数据库中提取有序数据。我正试图根据用户个人资料的浏览量在我的主页上列出他们 我的Ruby on rails 为什么可以';我不能从数据库中提取有序数据吗?,ruby-on-rails,ruby,sqlite,Ruby On Rails,Ruby,Sqlite,我似乎无法从数据库中提取有序数据。我正试图根据用户个人资料的浏览量在我的主页上列出他们 我的用户模式如下所示: # == Schema Information # # # Table name: users # # id :integer not null, primary key # email :string(255) # created_at :datetime not null # upda
用户
模式如下所示:
# == Schema Information
#
#
# Table name: users
#
# id :integer not null, primary key
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# username :string(255)
# password_digest :string(255)
# views :integer
#
我的控制器:
class PagesController < ApplicationController
def home
@users = User.order("'views' DESC")
end
end
进行客户端排序是可行的,但是我想给用户分页,所以这不是一个选项。任何建议都将不胜感激
@users = User.order("views DESC")
检查
对于分页,您可以使用此gem获得一些帮助:
检查
对于分页,您可以使用此gem获得一些帮助:
视图周围的'
是导致查询失败的原因。请尝试不使用引号:
User.order(“views DESC”)
视图周围的'
是导致查询失败的原因。请尝试不使用引号:
User.order(“views DESC”)
您在一个不变的字符串上进行订购;取消引用。您在一个不变的字符串上进行排序;取消报价,谢谢。现在一切正常。谢谢你的链接。谢谢。现在一切正常。谢谢你的链接。
@users = User.order("views DESC")