Rails display table alphabetically -
i want display entirety of user table alphabetically, know needs done in controller: code have been using in controller :
class userscontroller < applicationcontroller @users = user.find(:all) @users.sort! { |a,b| a.name.downcase <=> b.name.downcase } ... end
form code :
<% @users.each |user| %> <tr> <td><%= user.name %></td> </tr> <% end %>
receiving error undefined method `downcase' nil:nilclass
what have missed? thank you.
you should add order clause query.
@users = user.reorder(:name)
i not sure going if have significant number of users should add limit or pagination this.
Comments
Post a Comment