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. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 June 2011 11:07, Adel Mediouni <mediouni.adel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 %> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
dont care about the temp ligne lol, i forget to erase it :) On Jun 7, 12:26 pm, Adel Mediouni <mediouni.a...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 %> > > <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 %>-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 7 June 2011 11:26, Adel Mediouni <mediouni.adel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
yes its users not user :s i will the sort_by method its a good think :) thanks 2011/6/7 Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>> On 7 June 2011 11:26, Adel Mediouni <mediouni.adel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Mediouni Adel Tunis www.metal-tn.xooit.com -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tuesday, June 7, 2011 6:26:16 AM UTC-4, Adel Mediouni 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: <tr align="center" bgcolor="<%= cycle(''#D8D8D8'', ''#E6E6E6'') %>" > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/bUhfRmxyWERzcVlK. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
:) 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 Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org>> On Tuesday, June 7, 2011 6:26:16 AM UTC-4, Adel Mediouni 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: > > <tr align="center" bgcolor="<%= cycle(''#D8D8D8'', ''#E6E6E6'') %>" > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/bUhfRmxyWERzcVlK. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- Mediouni Adel Tunis www.metal-tn.xooit.com -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.