You seem to be trying to partially use restful design. I think that the "rails way" would be to use a routing like this:
map.resources :groups do | group | group.resources :members end
And then have a restful controller design for the members controller.
Instead of a special add_members action you would use the normal rest actions
class MembersController < ApplicationController
before_filter :load_group
def load_group @group = Group.find(params[:group_id]) end
# GET /groups/1/members/new # GET /groups/1/members/new.xml def new # get a list of members to present to the user to add to the group. # the actual set of members which can be added is determined by # business logic in the group model. # The form rendered by the new action should set params[:id] to the # id of the member selected. It also needs to set params[:group_id] to # the id of the group. The best way to do this is via a hidden field on the form
@members = @group.potential_new_members
respond_to do |format| format.html # new.html.erb format.xml { render :xml => @member } end end
# POST /groups/1/members # POST /groups/1/members.xml def create
respond_to do |format| # The group model should have a method to add a member, possibly with # some validition. It should return false/nil if the add operation fails if @group.add_member(Member.find(params[:id])) flash[:notice] = 'Member was successfully created.' format.html { redirect_to(group_member_path(@group, @member)) } format.xml { render :xml => @member, :status => :created, :location => @member } else format.html { render :action => "new" } format.xml { render :xml => @member.errors, :status => :unprocessable_entity } end end end end
The url to prompt for a new member to be added to group 1 would be
/groups/1/members/new
If you really wanted to allow /groups/1/addmembers you could add an additional route.