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

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

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