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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
stephen.celis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-12 16:29 UTC
Re: REST Design Question
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!
On Jan 12, 2:41 am, pankaj
<pankajbhage...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---