# Adding Query String to Link

**URL:** <https://www.ruby-forum.com/t/adding-query-string-to-link/110612>\
**Category:** Rails\
**Created:** [July 28, 2007, 4:48am UTC](https://www.ruby-forum.com/t/adding-query-string-to-link/110612 "2007-07-28T04:48:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eboss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ea666f/32.png) [@eboss](https://www.ruby-forum.com/u/eboss)\
**Post date:** [July 28, 2007, 4:48am UTC](https://www.ruby-forum.com/t/adding-query-string-to-link/110612/1 "2007-07-28T04:48:39Z")

</div>

I am using ThickBox/jQuery for an app. With it I need to be able to add  
a query string to the end of a dynamically generated URL. For example  
‘?height=300&width=300’

This is how my links are generated

\<%= link\_to @testimonial.customer, testimonial\_url(:id =\>  
@testimonial.id), :class =\> ‘thickbox’ %\>

How do I add the query string to the end of that URL?

I found a semi working solution in :anchor like

\<%= link\_to @testimonial.customer, testimonial\_url(:id =\>  
@testimonial.id, :anchor =\> ‘?height=300&width=300’), :class =\>  
‘thickbox’ %\>

But I would like to do it right so I know there are no bugs.

---

<div class="post-metadata">

**Author:** ![eboss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ea666f/32.png) [@eboss](https://www.ruby-forum.com/u/eboss)\
**Post date:** [July 28, 2007, 6:28am UTC](https://www.ruby-forum.com/t/adding-query-string-to-link/110612/2 "2007-07-28T06:28:39Z")

</div>

Jeremy L. wrote:

> 

I ran into the same issue last week and your code led me to the  
solution.  
Looks like unreserved keys that are passed to the options hash url\_for,  
which is what testimonial\_url calls down the line, get turned into query  
string params. So:

\<%= link\_to @testimonial.customer, testimonial\_url(:id =\>  
@testimonial.id, :height =\> 300, :width =\> 300), :class =\>  
‘thickbox’ %\>

Thanks for helping me! Hope this helps you.

* * *

## Ryan Carmelo Briones

View this message in context:  
[http://www.nabble.com/Adding-Query-String-to-Link-tf4161058.html#a11839641](http://www.nabble.com/Adding-Query-String-to-Link-tf4161058.html#a11839641)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).
