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.

On 7 June 2011 11:07, Adel M. [email protected] wrote:

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

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

SO this is the view:

<%= sortable_column "username" %> <%= sortable_column "email" %> <%= sortable_column "sign_in_count" %> <%= sortable_column "amis" %> <% 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 %> >

<%= user.username %>
<%= user.email %>
<%= user.sign_in_count %>
<%= user.contacts.count %>
<%= link_to ‘Show’, user %>
<%= link_to ‘Edit’, edit_user_path(user) %>
<%= link_to ‘Destroy’, user, :confirm => ‘Are you
sure?’, :method => :delete %> <% end %>

On 7 June 2011 11:26, Adel M. [email protected] wrote:

<% temp = ActiveRecord::Base.connection.select_one("select sure?', :method => :delete %> <% 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

yes its users not user :s
i will the sort_by method its a good think :slight_smile:
thanks

2011/6/7 Colin L. [email protected]

<% end %> <%= link_to 'Destroy', user, :confirm => 'Are you

Colin


Mediouni Adel
Tunis
www.metal-tn.xooit.com

On Tuesday, June 7, 2011 6:26:16 AM UTC-4, Adel M. wrote:

<% i = i +1 %>
<% if i.modulo(2) == 0 %>
<% color = ‘#E6E6E6’ %>
<% else %>
<% color = ‘#D8D8D8’ %>
<% end %>
<tr align=center bgcolor = <%= color %> >

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 !!?

2011/6/7 Tim S. [email protected]

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Mediouni Adel
Tunis
www.metal-tn.xooit.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs