Topic: Routing Conundrum

Where does route.rb get its information about the current request?  My (seemingly mistaken) impression was that the environment variables REQUEST_URI and REQUEST_GET are used.

Here's why that cannot be the complete answer:

I have this route

  map.connect '*anything',

which works as expected using the console with the following two tests

1) I manually enter environment values for REQUEST_URI and REQUEST_GET and run Dispatcher.dispatch

2) I make a ActionController::Routing::Routes and run recognize_path

both give me the :controller, :action, and :anything that I expect to get.

But when I run thru Apache (2.0 on a new HighSpeedRails account), params[:anything]
is different: it remains empty no matter what URI is given to the browser.

I know the problem is not the values of REQUEST_URI and REQUEST_GET because I have
tested the environment values gotten by rails.  Even though params[:anything] is
empty these environment values are right on the one money with requests having as
many constituent parts as I have had the patience to try.


I am a newbie to rails.  Before this I have only played around with InstantRails.  As
things are, I have never managed to run any application on my HighSpeedRails server that
requires a nontrivial URI.

Re: Routing Conundrum

About my routing conundrum.  I have placed an example at It
will be there until 7pm CDT on July 5th when I'll probably start fooling around looking for my own solution to the conundrum.

Just enter

where the part following is period-less and nonempty.  Then
you will see what is bothering me.  (If you enter an empty path or a
path with a period my setup will avoid Rails altogether and look for
static pages thru Apache. No problems there!)

Again, I intend for this example to go away after 7pm CDT on July 5, 2007.

Re: Routing Conundrum

I think the problem you have there is that in the route, you need to specify what is passed as a parameter.  If you look at the default route, you have ':controller/:action/:id', so you can access id for example with params[:id]. In your route, you have *anything which doesn't specify any parameters that are available to you in the application. I would recommend taking a look at "Agile Web Development with Rails" as they have a good section on routing.

Re: Routing Conundrum


Not using the standard parameters would not explain why *anything shows exactly what it should
when I test from the console.

You are, of course, right that I do not want to set my application up with *anything.  I
only am doing so now to help illustrate my problem (to myself and to others). 

Happens I got the idea of using *anything from the very chapter you suggest I ought to read.
I have not only read that material but also the relevant parts of the shortcut "Routing Rails" available from Addison Wesley. 

Thanks anyway.

Does Rails have a debug mode that causes routes.rb to ignore the REQUEST_URI environment
variable?  Could I have inadvertantly turned that on?   I have set RAILS_ENV to development
so I don't think I'm running in testing mode.

Re: Routing Conundrum

My problem is solved.  My solution is consistent with the following assumptions:  Dispatching is done on the basis the the environment variable REQUEST_URI only if SCRIPT_NAME is unavailable.  If using SCRIPT_NAME, dispatching wants no leading /.  This is the way things are if you follow the usual advice and use .htaccess for your rewrite rules.  If you do as I have done and eliminate .htaccess, then you need to arrange for SCRIPT_NAME to be like REQUEST_URI but without the leading /.

My goals BTW were to avoid the overhead of .htaccess, to keep my static files separate from Rail's cached files, and to serve up my static files without any intervention from Rails.  Kinda extravagant for a newbie but I got there.  (I suppose though that another version of Rails may break my solution.  Sigh.)