Query_string examples?


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


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


Bogdan I. wrote:

The parameters are stored in the params hash

Bogdan, thanks for the tip. It works great! Dan.