i have a table of data in my application. i would like to be able to sort the data in the table by clicking on the column header. the way i was thinking i want to do this is just by making a ''sort'' action, and then calling the sort action from each link in the table header (passing the respective column name). it doesn''t seem to be possible to pass parameters to an action though. do i just have to use forms for this, or how could it be done? thanks, cam --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I think that any additional params you add to your link_to function call that are not specifically expected in the function call (like :id => x) will just be passed through in the GET query string. For instance... link_to(:controller => ''controller'', :action => ''sort'', :sort_order => ''date'') link_to(:controller => ''controller'', :action => ''sort'', :sort_order => ''firstname'') link_to(:controller => ''controller'', :action => ''sort'', :sort_order => ''lastname'') should produce links along the lines of: http://yoursite.dom/controller/sort?sort_order=date http://yoursite.dom/controller/sort?sort_order=firstname http://yoursite.dom/controller/sort?sort_order=lastname In your controller, params[:sort_order] will have a value of ''date'', ''firstname'', or ''lastname'' depending on the link clicked. You can check it and act appropriately with your Object.find call. If you really want to DRY it up, the value of sort_order used in the links and passed in can be the name of the field to sort by, so you could just use that in your Object.find call. c. Cameron Matheson wrote:> i have a table of data in my application. i would like to be able to > sort the data in the table by clicking on the column header. the way > i was thinking i want to do this is just by making a ''sort'' action, > and then calling the sort action from each link in the table header > (passing the respective column name). it doesn''t seem to be possible > to pass parameters to an action though. do i just have to use forms > for this, or how could it be done? > > thanks, > cam-- 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 -~----------~----~----~----~------~----~------~--~---
Thanks! I''ve been wondering how to use arbitrary GET parameters for a while now. Cam On 10/22/06, Cayce Balara <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I think that any additional params you add to your link_to function call > that are not specifically expected in the function call (like :id => x) > will just be passed through in the GET query string. For instance... > > link_to(:controller => ''controller'', :action => ''sort'', :sort_order => > ''date'') > link_to(:controller => ''controller'', :action => ''sort'', :sort_order => > ''firstname'') > link_to(:controller => ''controller'', :action => ''sort'', :sort_order => > ''lastname'') > > should produce links along the lines of: > > http://yoursite.dom/controller/sort?sort_order=date > http://yoursite.dom/controller/sort?sort_order=firstname > http://yoursite.dom/controller/sort?sort_order=lastname > > In your controller, params[:sort_order] will have a value of ''date'', > ''firstname'', or ''lastname'' depending on the link clicked. You can check > it and act appropriately with your Object.find call. If you really want > to DRY it up, the value of sort_order used in the links and passed in > can be the name of the field to sort by, so you could just use that in > your Object.find call. > > c. > > > Cameron Matheson wrote: > > i have a table of data in my application. i would like to be able to > > sort the data in the table by clicking on the column header. the way > > i was thinking i want to do this is just by making a ''sort'' action, > > and then calling the sort action from each link in the table header > > (passing the respective column name). it doesn''t seem to be possible > > to pass parameters to an action though. do i just have to use forms > > for this, or how could it be done? > > > > thanks, > > cam > > > -- > 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 -~----------~----~----~----~------~----~------~--~---
http://wiki.rubyonrails.org/rails/pages/SortHelper might help ya :) Cameron Matheson wrote:> i have a table of data in my application. i would like to be able to > sort the data in the table by clicking on the column header. the way > i was thinking i want to do this is just by making a ''sort'' action, > and then calling the sort action from each link in the table header > (passing the respective column name). it doesn''t seem to be possible > to pass parameters to an action though. do i just have to use forms > for this, or how could it be done? > > thanks, > cam-- 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 -~----------~----~----~----~------~----~------~--~---