我想按日期排序,我在降序列表,它作为一个“新用户列表”,在数据库中我有一列是按日期排序在Ruby中降序排列轨
t.datetime "created_at", null: false
这是当一个新用户注册,在视图中,我有这样的代码的时间:
%table.table.table-striped.table-hover
%thead
%h3 New Users
%hr
%th Name
%th Company
%th Role
%th Created date
%th{:width => '50'}
%th{:width => '50'}
%th{:width => '50'}
%tbody
- @users.each do |user|
-if user.role == "trial-member"
- @created_at.sort{|a,b| b.created_at <=> a.created_at}.each do |created_at|
%tr
%td
= user.first_name
= user.last_name
%td= user.company
%td= user.role
%td= user.created_at
%td= link_to 'Approve', edit_user_path(user), {:class => 'btn btn-success btn-sm'}
,但是这给了“为无未定义的方法`排序”:NilClass”的错误,我拿什么是否按创建日期降序对表中的列表进行排序?谢谢。
对于那些低估了这个问题的人,请向提问的人提供可操作的反馈,以便他们改进。让我们的社区更加棒! – Justin