The documentation fails me. What''s the rails way of creating a url like: http://some.other.external.url/page?param=asdf&another_param=asdf ? Thanks, Joe
On 8/24/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The documentation fails me. > > What''s the rails way of creating a url like: > http://some.other.external.url/page?param=asdf&another_param=asdf ?And another stupid question: Say I want to retrieve the data at that URL. What Ruby/Rails functions would I want to use for that?
On 8/24/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 8/24/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > The documentation fails me. > > > > What''s the rails way of creating a url like: > > http://some.other.external.url/page?param=asdf&another_param=asdf ? > > And another stupid question: Say I want to retrieve the data at that > URL. What Ruby/Rails functions would I want to use for that?Try this: <%= link_to("Some Other", :controller => "page", :param => "asdf", :another_param => "asdf") %> You should find all parameters in @params <%= @params.inspect %>
> On 8/24/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > http://some.other.external.url/page?param=asdf&another_param=asdf ?Also, you may want to check out documentation on url_for()
Joe Van Dyk wrote:> On 8/24/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > And another stupid question: Say I want to retrieve the data at that > URL. What Ruby/Rails functions would I want to use for that?be u the url string: #1. using Net::HTTP res = Net::HTTP.get_response(URI.parse(u)) #res is a Net::HTTPResponse object e.g. p res.body #2. using open-uri require ''open-uri'' open(u) {|f| f.each_line {|line| p line} #f is a file like object } Bye Luca
James Earl wrote:> <%= link_to("Some Other", :controller => "page", :param => "asdf",:another_param => "asdf") %>> Also, you may want to check out documentation on url_for()I''d say the same, but looking to the docs/source it seems that both these methods resolve the url by taking into account the locally defined routes, is it possbile that a route or a controller migth interfere with the url composition (e.g. if I have a controller "page" locally that is server by the url "/mypage")? bye Luca
On 8/25/05, Luca Mearelli <l.mearelli-agQh1g0/mj82c7tr79CZ2gC/G2K4zDHf@public.gmane.org> wrote:> Joe Van Dyk wrote: > > On 8/24/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > And another stupid question: Say I want to retrieve the data at that > > URL. What Ruby/Rails functions would I want to use for that? > > be u the url string: > > #1. using Net::HTTP > res = Net::HTTP.get_response(URI.parse(u)) > #res is a Net::HTTPResponse object e.g. > p res.body > > #2. using open-uri > require ''open-uri'' > > open(u) {|f| > f.each_line {|line| p line} #f is a file like object > }I had tried that, but it failed on a URL like "https://some.url:port/blahblah/blahblah?asdf=foo". It said it was a bad URL.
Joe Van Dyk wrote:> > I had tried that, but it failed on a URL like > "https://some.url:port/blahblah/blahblah?asdf=foo". It said it was a > bad URL.didn''t try with https, on my machine (XP pro with ruby 1.8.2 single click install) but open-uri fails with an "ArgumentError: open-uri doesn''t support https." whereas Net::HTTP you can have a look at samples\Ruby-1.8.2\sample\openssl\wget.rb (just tried it and it works) bye Luca