I am a newcomer to RoR and have a question about routing. I have set up an application and a simple user login system (yes I know there is already a login generator out there, I just wanted to try it for myself). I have a before_filter on a certain action that checks if the user is logged in or not. If not, it redirects them to the login page. This is how I have it routed, does this look right?
map.resources :user, :collection => { :login => :get }
also, why if I change
:login => :get
to
:login => :post
does it display the ‘show’ view?
will correspond to a URL like “/users/login”
will correspond to a URL like “/users/123/login”
Because :user is referring to a resource, it will map the url to an action depending on the request method in addition to the url.
So, the first route above will map a GET to /users/login to the login action,
but when you change it to :post, it will then map a GET to /users/login to the default, which is the ‘users’ controller and ‘show’ action for a User with an ID of ‘login’ – which is not what you want.
(and it will map a POST to /users/login to the ‘login’ action)