sortable values

hi, i want make a view with a table that i can sort, but values in this table dont comes from one model. for real its a table of users but in the end it show how contact have this user ( user.contacts.count ). i can see the table,i can sort columns except the last ("friends" ). how can i resolve this probleme please.

Can you post the code displaying the table so that we can understand the problem better please.

Colin

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 %>

dont care about the temp ligne lol, i forget to erase it :slight_smile:

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

yes its users not user :s

i will the sort_by method its a good think :slight_smile:

thanks

Not related to your problem, but there’s an easier way to do this part of your code using a helper:

:slight_smile: thank you

im a beginer in ror,and i dont know whats the importance of the helper o_O !! and what is the difference between run a task (in file .rake) or write the method directly in the controller !!?