REST Design Question

I have 2 models Roles and Rights with many to many Relationship.

Without Rest: Controller: Action Roles: list,edit,create,destroy,map_rights Rights: list,edit,create,destroy,list_by_role

NOTE: map rights function will map/unmap multiple rights to a particular role using a list of checkboxes.

What would be the design following Rest ?

Regards, Pankaj

With REST:

Roles: index, new, create, edit, update, destroy Rights: index, new, create, edit, update, destroy

Now, I guess, an explanation.

List and index should be interchangeable; just get rid of 'list' for 'index'.

I assume there's a means of creating these rights/roles from the first place. This form would usually be in a 'new' action (the form POSTs to 'create'). And while 'edit' is good to provide a GET form for a record, the form would post (using PUT) to 'update' to write the changes. 'Destroy' stays.

'map_rights' seems to be an 'update' action if it's modifying that role's rights.

And finally, 'list_by_role' could be achieved with the following established routes:

# config/routes.rb map.resources :roles, :has_many => :rights map.resources :rights

Now you have role_rights_path(@role), which will allow you to use the RightsController#index action to list just the rights of a particular role, as long as @role is established from params[:role_id]. You could just detect with a before_filter:

# app/controllers/rights_controller.rb before_filter :get_rights

protected

def get_rights   if @role = Role.find params[:role_id]     @rights = @role.rights   else     @rights = Right.find :all   end end

Now, the following two URLs will 'list' rights and 'list_by_role' with ID 1 http://0.0.0.0:3000/rights http://0.0.0.0:3000/roles/1/rights

Now, go convert all those crudful controllers!