views:

561

answers:

1

I am struggling with the route setup for a Rails application. I have installed restful_authentication and mostly followed the instructions. I have set up the routes this way:

map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.resource :session

If you're not logged in, you're redirected to http://localhost:3000/session/new. It makes some kind of sense, as the code in lib/authenticated_system.rb says redirect_to new_session_path.

But I thought the routes mapping was supposed to work both ways (code to URL and URL to code). Can someone explain? Thanks

+3  A: 

map.resource :session creates a few named resources for you including new_session_path (see ActionController::Resources).

map.login and map.logout are just helper routes to make your code easier to understand. map.login (which generates login_path) points to the same controller/action combo as new_session_path does, it's just easier to remember at a glance what it does.

Michael Sepcot
I understand map.login does not create new_session_path (I understood this, as my code blew up) but login_path. I'll replace new_session_path with login_path in the lib. Thanks.
Christian Lescuyer