On 7 June 2011 11:26, Adel Mediouni <mediouni.a...@gmail.com> wrote: > SO this is the view: > > <tr bgcolor='#A4A4A4'> > <th> <%= sortable_column "username" %> </th> > <th> <%= sortable_column "email" %></th> > <th> <%= sortable_column "sign_in_count" %></th> > <th> <%= sortable_column "amis" %></th> > <th></th> > <th></th> > <th></th> > </tr> > <tr height="4px"><td></td></tr> > <% i = 0 %> > <% @user.each do |user| %> > > <% i = i +1 %> > <% if i.modulo(2) == 0 %> > <% color = '#E6E6E6' %> > <% else %> > <% color = '#D8D8D8' %> > <% end %> > <% temp = ActiveRecord::Base.connection.select_one("select > count(person_id) amis from contacts where user_id =" + user.id.to_s) > %> > <tr align=center bgcolor = <%= color %> > > <td><%= user.username %></td> > <td><%= user.email %></td> > <td><%= user.sign_in_count %></td> > <td><%= user.contacts.count %></td> > <td><%= link_to 'Show', user %></td> > <td><%= link_to 'Edit', edit_user_path(user) %></td> > <td><%= link_to 'Destroy', user, :confirm => 'Are you > sure?', :method => :delete %></td> > </tr> > <% end %>
I expect there is a better way but in the controller you could just use @sorted_users = @users.sort_by {...} to sort the users by contacts.count. I notice in the code you are using @user but I assume you mean @users, it should be plural since it contains a number of users. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.