Forum: Ruby on Rails "true" wildcard in routes.rb

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A0cde27dad03b3f8ca2f16a3a5e817a1?d=identicon&s=25 Lasse Koskela (lkoskela)
on 2005-12-09 15:35
Hi,

I'd like to catch certain type of URLs that follow the pattern
"http://server.com/map/http://www.another.com/url/w...
and map that to a controller which gets *whatever comes after "/map/" as
a single variable.

I already tried the following mapping:

  map.connect '/map/*all',
              :controller => 'urlmapper',
              :action => 'test',
              :all => /.*/

and in the controller then concatenating the resulting "all" array into
a single string, but that only works when there's no URL request
parameters ("?foo=bar").

What would be the "Rails way" to do what I'm describing here?

And thanks for "listening" :)
10d9ed7ab11115b081bb36f56a7a13bc?d=identicon&s=25 johnwilger (Guest)
on 2005-12-09 19:18
(Received via mailing list)
On 12/9/05, Lasse Koskela <lasse.koskela@gmail.com> wrote:
> and in the controller then concatenating the resulting "all" array into
> a single string, but that only works when there's no URL request
> parameters ("?foo=bar").

You need to URL encode the '?' if you don't want it to be picked up as
a querystring separator.

--
Regards,
John Wilger
http://johnwilger.com

-----------
Alice came to a fork in the road. "Which road do I take?" she asked.
"Where do you want to go?" responded the Cheshire cat.
"I don't know," Alice answered.
"Then," said the cat, "it doesn't matter."
- Lewis Carrol, Alice in Wonderland
A0cde27dad03b3f8ca2f16a3a5e817a1?d=identicon&s=25 Lasse (Guest)
on 2005-12-09 19:26
johnwilger wrote:
> On 12/9/05, Lasse Koskela <lasse.koskela@gmail.com> wrote:
>> and in the controller then concatenating the resulting "all" array into
>> a single string, but that only works when there's no URL request
>> parameters ("?foo=bar").
>
> You need to URL encode the '?' if you don't want it to be picked up as
> a querystring separator.

Thanks John. I was aware of the query string being treated as a query
string. I'm just wondering if someone somewhere has already implemented
some kind of a utility/tweak to "fake" the path and query string into a
single string.

Can we access the original request URL from a controller?

-Lasse-
A0cde27dad03b3f8ca2f16a3a5e817a1?d=identicon&s=25 Lasse <lasse.koskela@gmail.com> (Guest)
on 2005-12-09 19:36
Lasse wrote:
> Can we access the original request URL from a controller?

Sorry for asking something that's in the RDocs... Yeah, there's
"request.request_uri" which returns the full path including query
string. I suppose I could just parse that to pick up the URL from the
end.
42292bf8a0acbc98862d9306b501275d?d=identicon&s=25 Rabbit (Guest)
on 2005-12-13 01:38
(Received via mailing list)
No need to parse.

A route like:
map.connect 'serve/*commands', :controller => 'serve'

Will yield an array called 'commands' in your controller. :)

- Rabbit

---
42292bf8a0acbc98862d9306b501275d?d=identicon&s=25 Rabbit (Guest)
on 2005-12-13 01:44
(Received via mailing list)
I should note that 'commands' is available in params.
(params[:commands])

- Rabbit

---
This topic is locked and can not be replied to.