What''s the current method for having column headings that when you click on them, sort your view according to that column heading? I used the sortable_columns plug in in the past, but it seems a force-fit for Rails 2.0 respond_to ... format.html -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jim Tobin wrote:> What''s the current method for having column headings that when you click > on them, sort your view according to that column heading? I used the > sortable_columns plug in in the past, but it seems a force-fit for Rails > 2.0 respond_to ... format.htmlI decided to use a helper method when I did this recently to account for columns which would be sorted on a related model''s value, rather than the id in the column. The helper I am using is: def project_sort_header column_name, display_as = nil display_as ||= column_name.to_s.humanize link_to display_as, project_list_path(:sort => column_name) end In my view, I have table headings defined thusly: <th><%= project_sort_header ''groups.name'', ''Group'' %></th> <th><%= project_sort_header :title %></th> <th>Description</th> <th><%= project_sort_header :priority %></th> <th><%= project_sort_header ''users.username'', ''Owner'' %></th> And in the controller: order = params[:sort] || :priority @projects = Project.find ;all, :order => order, :include => ... For multiple models, the helpers can be DRYd by passing in the table type and using self.send and constructing the xxx_list_path method from the table type. -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jokrish wrote:> i want to know more about sorting in ruby.Sorting is handled by your call to the model''s find method; so to make it user selectable, you use a conditions hash with the find method so you can insert the field name the user clicked on into the find conditions. http://api.rubyonrails.org/classes/ActiveRecord/Base.html The explanation of Conditions is the second section on that page. Check out Ryan Bates Railcasts on the subject... here''s one that should give you some ideas: http://railscasts.com/episodes/15 -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---