我想按日期排序,我在降序列表,它作爲一個「新用戶列表」,在數據庫中我有一列是按日期排序在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