Adding Query String to Link


#1

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.


#2

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
Sent from the RubyOnRails Users mailing list archive at Nabble.com.