"true" wildcard in routes.rb


#1

Hi,

I’d like to catch certain type of URLs that follow the pattern
http://server.com/map/http://www.another.com/url/with.php?possible=arguments
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” :slight_smile:


#2

On 12/9/05, Lasse K. removed_email_address@domain.invalid 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 W.
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

#3

johnwilger wrote:

On 12/9/05, Lasse K. removed_email_address@domain.invalid 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-


#4

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.


#5

No need to parse.

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

Will yield an array called ‘commands’ in your controller. :slight_smile:

  • Rabbit


#6

I should note that ‘commands’ is available in params.
(params[:commands])

  • Rabbit