views:

1423

answers:

4

I never touch routes.rb beyond calling map.root to set a default route. I've always been content to use URLs of the form...

/controller/action/perhaps_an_id

and it works fine.

Does this make me a bad person? Am I missing out on something totally awesome?

What if I try to adopt RESTful design? Would that mean I have to edit routes.rb or could I continue to pleasantly ignore it?

(I tried to read up on this topic in The Rails Way but it was unbearable.)

+5  A: 

It looks like you already know the answers to these questions and are just trolling a bit here. Anyway, I'll bite.

Not having switched to RESTful design does not make you a bad person and if you feel no need to change keep writing your apps the 1.x way.

The majority of Rails developers has adopted REST and seems to be very happy about it. I don't think there is a need here to repeat all pro REST arguments.

You do need to add one line per resource to your routes file such as:

map.resources :posts

Happy New Year 2009

allesklar
No, not trolling. I really wanted to know.
Ethan
+4  A: 

If you were to go RESTful, yes you would have to edit routes.rb and add your resources like,

map.resources :your_resource

or if you have nested resources,

    map.resources :people do |person|
      person.resources :ideas do |idea|
        ideas.resources :bad_ones
      end
    end
Ronn
+5  A: 

You may also want to make custom named routes for your marketing department (eg: mycoolsite.com/free-trial) that go off to specific controllers and actions, etc.

Ryan Bates has a series of screencasts that go over some of the neat things you can do with routes: http://railscasts.com/tags/14

Derek P.
+4  A: 

If you generate your resources with the default scaffolding then it will even include the restful routing for you in routes.rb.

If you're not using the scaffolding then the reason that it's working is because of the default routes at the bottom by default:

    map.connect ':controller/:action/:id'
    map.connect ':controller/:action/:id.:format'

I've been following that it's best practice to remove these for production applications and instead make sure that only the resources that need to be exposed are exposed. With Rails 2.2 you can even limit the RESTful methods from map.resources by:

map.resources :posts, :only => [:index, :show]
map.resources :comments, :except => [:edit]

There's also tons of cool things you can do with nested resources, named routes, etc. They have a lot of examples in the docs (http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M000255&name=resources)

Dan McNevin