routing problem with beginner tutorial app

I'm just getting started with Rails 2. Plus, it's been a while since I played with Rails at all. So to explore, I whipped out an old Rails tutorial (from an O'Reilly book) and started going through it, to refresh my memory. This is just a simple "Hello world" experiment.

I created my rails app, cd'd into it, started the server, and created a simple controller:

  script/generate controller greeting

So I tried to talk my controller in the browser:

  http://localhost:3000/greeting

And I got a routing error, "no route matches ... with method get".

I found this a bit hard to understand, because routes.db has the default routes, so my controller name should work from a GET request. But, nothing daunted, I added some overkill routing at the top of routes.db:

  map.resources :greeting

Now http://localhost:3000/greeting was routed properly; of course there was no index action but now at least I got the expected error message telling me so, I wrote an index method, and all was well; hello, world.

But here's the weird part. I then *deleted* the map.resources line from routes.db, and my app nevertheless continued working. I can rake routes and sure enough only the default routes are in force. So it looks like maybe this a bug in Rails, where it takes some manual jiggering to get the default routes operating properly? Anyway I figure this must be well known, so maybe someone could just explain it to me? No big deal, but I like to understand what's going on, if possible - thx - m.

Get a habit to restart your development server after each change in routes.rb. And in models. Actually, I'm restarting the server a lot more times, than I probably should. But it's better than fight with silly bugs which are not even exist.

mattn wrote:

I'm just getting started with Rails 2. Plus, it's been a while since I played with Rails at all. So to explore, I whipped out an old Rails tutorial (from an O'Reilly book) and started going through it, to refresh my memory.

Do not use old Rails tutorials with new versions of Rails.

Do not use old versions of Rails for new projects...

[...]

But here's the weird part. I then *deleted* the map.resources line from routes.db, and my app nevertheless continued working.

If you are using a version of Rails before 2.3, you need to restart the server for routing changes to take effect.

I can rake routes and sure enough only the default routes are in force.

Right, because rake loads a new instance of the Rails environment, and so it picks up the changes in the routes file.

So it looks like maybe this a bug in Rails, where it takes some manual jiggering to get the default routes operating properly? Anyway I figure this must be well known, so maybe someone could just explain it to me? No big deal, but I like to understand what's going on, if possible - thx - m.

No bug. No manual jiggering. Your routes file just got out of sync with what the server already had in memory.

Best,