I''m listing something (people, say) in a column at the left of my page, and in a column to the right, I''d like to have some links that would let the site reader choose the listing order (by age, by name, etc.) In PHP I''d do that by a query string, i.e. I''d keep using the same webpage, but my links would tack on strings such as (pagelink)&orderby=age etc. Is there a way to do this sort of thing in Rails? I note that the AWDWR2 index has only one item under "Q", and this isn''t it! I also note that a search on this list doesn''t produce a lot of hits on "query_string". This is making me suspect that we''re supposed to do things differently in rails. I''m hoping that someone advise me on this, before I start going down a path of not-best practice. PS. I hope the answer isn''t that I should write a separate view method for each ordering scheme. That seems to violate the DRY principle, since the only thing that would be different in the methods be a single :order phrase in a single line of code -- 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 -~----------~----~----~----~------~----~------~--~---
The parameters are stored in the params hash http://localhost/people/show?order=name will automatically initialize your params hash like this params={:controller=>"people",:action=>"show",:order=>"name"} In your view you would probably have <%= link_to("Order by whatever", :action=>''show'',:order=>''whatever'') %> When the user clicks that, in your controller params[:order] will be ''whatever'' and you can order by that On 3/18/07, Dan Kelley <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''m listing something (people, say) in a column at the left of my page, > and in a column to the right, I''d like to have some links that would let > the site reader choose the listing order (by age, by name, etc.) > > In PHP I''d do that by a query string, i.e. I''d keep using the same > webpage, but my links would tack on strings such as > > (pagelink)&orderby=age > > etc. Is there a way to do this sort of thing in Rails? I note that the > AWDWR2 index has only one item under "Q", and this isn''t it! I also > note that a search on this list doesn''t produce a lot of hits on > "query_string". This is making me suspect that we''re supposed to do > things differently in rails. > > I''m hoping that someone advise me on this, before I start going down a > path of not-best practice. > > PS. I hope the answer isn''t that I should write a separate view method > for each ordering scheme. That seems to violate the DRY principle, > since the only thing that would be different in the methods be a single > > :order > > phrase in a single line of code > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Bogdan Ionescu wrote:> The parameters are stored in the params hashBogdan, thanks for the tip. It works great! Dan. -- 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 -~----------~----~----~----~------~----~------~--~---