views:

30

answers:

2

How would I either create a helper or use the built-in link_to helper to combine URL params?

For instance, say I'm on a page with the URL parameter of status:

http://example.com/items?status=new

I have another link for carriers that I'd basically want to append to that, like so:

http://example.com/items?status=new&carrier=fedex

So basically the helper would detect if there were any params in the URL and then append the param to that.

A: 

Just pass it as a hash, i.e. items_url(:status => :new, :carrier => :fedex)

glebm
But that does nothing for detecting the current URL. I need the helper to know if the current URL already has params in it and grab them.
Shpigford
params.present?
glebm
A: 

You want to use the request object. Here is a good writeup on it:Request Object in Rails

sosborn