Forum: Ruby on Rails query_string examples?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
94d4d7d1b78391266fea8e739c9405c5?d=identicon&s=25 Dan Kelley (dankelley)
on 2007-03-18 22:28
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


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


phrase in a single line of code
531eb73f8fbf05a197721d02b4e6aadb?d=identicon&s=25 Bogdan Ionescu (Guest)
on 2007-03-19 00:22
(Received via mailing list)
The parameters are stored in the params hash
http://localhost/people/show?order=name will automatically initialize
params hash like this

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
94d4d7d1b78391266fea8e739c9405c5?d=identicon&s=25 Dan Kelley (dankelley)
on 2007-03-19 01:32
Bogdan Ionescu wrote:
> The parameters are stored in the params hash

Bogdan, thanks for the tip.  It works great!  Dan.
This topic is locked and can not be replied to.