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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> <%=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¶m2=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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Shai, Thanks you very much for the detailed explanation! Now, I understand the behavior of link_to and url_for. Glenn --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Nov 19, 2007 5:31 PM, Glenn <withhawaii-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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}%>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 %> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maybe Matching Threads
- accessing extra request parameters
- HTML entities in URLs and urlencoding
- XML parameters to Column Headers for importing into a dataset
- multiplying values in data frame by corresponding value in the first column
- How to catch a parameter that contains a full url