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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -