John Small wrote:
map.resources :accounts,:new => { :authorize => :post }
what is :new => { :authorize => :post }
Shouldn't that be something like:
map.resources :accounts, :collection => { :authorize => :post }
But, this does bring up an interesting extension to this discussion
about resources.
In your example your mapping is essentially say this:
POST: http://example.com/accounts/authorize
According to this, sending a POST to authorize should "create" a new
account. That's not, however, what you're really wanting to do. What's
really going on in terms of REST is that you are creating a new session.
Session is not necessarily an ActiveRecord model object, yet it
certainly can be a resource. Now with that in mind, the design is back
to basic CRUD actions. No custom actions are required.
When you want a new session you POST to the session resource collection.
When you want terminal a session you send a DELETE to the session
resource collection. You can then back the session resource with it's
own controller containing the create and destroy actions.
It's also okay to have more than one URI that refers to the session
resource.
So:
POST: http://example.com/session
and
POST: http://example.com/login
Could both reference the same action of the same resource performing the
same function.
Likewise:
DELETE: http://example.com/session
and
POST: http://example.com/logout
Could also both have the same functionality of deleting an active
session effectively logging out.