title: Sort by date in descending order in ruby in rails
body: <p>I would like to sort my list in a descending order by date which as a "New user list", in the database I have a column which is </p>
  
  <pre><code>t.datetime "created_at",                                      null: false  
  </code></pre>
  
  <p>This is the time when a new user registered, in the view, I have the code like this:</p>
  
  <pre><code>%table.table.table-striped.table-hover
        %thead
        %h3 New Users
        %hr
          %th Name
          %th Company
          %th Role
          %th Created date
          %th{:width =&gt; '50'}
          %th{:width =&gt; '50'}
          %th{:width =&gt; '50'}
        %tbody
        - @users.each do |user|
          -if user.role == "trial-member"
            - @created_at.sort{|a,b| b.created_at &lt;=&gt; 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 =&gt; 'btn btn-success btn-sm'}
  </code></pre>
  
  <p>but this gives an error that "undefined method `sort' for nil:NilClass", what shall I do to sort the list in table descending by created date? Thank you.</p>