Add a query string parameter to link_to links

This is a little obscure, but easy enough.

If you want to add a query string parameter to a link generated using the link_to helper function, try the following:

link_to users_path(:filter => 'boss')

That will generate this link (for the example.com domain of course):

http://www.example.com/users?filter=boss

Simples.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s