Link_to and GET parameters

Hi,
I am trying to generate a link to external site with GET parameters
( in new window).
I tried following code, but it does not produce any parameters.

<%=link_to “Open New Page”, “https://www.foo.com/page/”, {:popup =>
true}, {:param1 => “value1”, :param2 => “value2”}%>

and

<%=link_to “Open New Page”, url_for(“https://www.foo.com/page/”,
{param1 => “value1”, :param2 => “value2”}) , {:popup => true}%>

Can anyone tell me what is wrong with my code or there is a
alternative way?

Thanks in advance.

Glen

<%=link_to “Open New Page”, “https://www.foo.com/page/”, {:popup =>
true}, {:param1 => “value1”, :param2 => “value2”}%>

<%=link_to “Open New Page”,
https://www.foo.com/page/?param1=value1&param2=value2",
{:popup => true} %>

if you are using a string option (rather than a hash parameter to
url_for) you need to go string all the way, and if you are using url_for
(which takes a hash) you need you need to go hash all the way

<%=link_to “Open New Page”, url_for(“https://www.foo.com/page/”,
{param1 => “value1”, :param2 => “value2”}) , {:popup => true}%>

<%=link_to “Open New Page”, url_for(:controller=>‘page’,
:action=>‘some’, :param1 => “value1”, :param2 => “value2”) , {:popup =>
true}%>

(url_for creates a url for you based on the configuration in your
routes.rb file.
hth

s

Hi Shai,

Thanks you very much for the detailed explanation! Now, I understand
the behavior of link_to and url_for.

Glenn

On Nov 19, 2007 5:31 PM, Glenn [email protected] wrote:

and

<%=link_to “Open New Page”, url_for(“https://www.foo.com/page/”,
{param1 => “value1”, :param2 => “value2”}) , {:popup => true}%>

You’ve seen that you can’t use url_for like this. In addition, you
should use Hash#to_query to create the query string and then escape
the HTML. This protects your link from XSS vulnerabilities and the
like:

<%= link_to “Open New Page”, h(‘https://www.foo.com/page?’ +
{:param1 => “value1”, :param2 => “value2”}.to_query), :popup => true
%>