# (Newbie) Help adding own actions to restful controllers to c

**URL:** <https://www.ruby-forum.com/t/newbie-help-adding-own-actions-to-restful-controllers-to-c/91083>\
**Category:** Rails\
**Created:** [April 4, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/newbie-help-adding-own-actions-to-restful-controllers-to-c/91083 "2007-04-04T15:02:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinlooker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/54ee81/32.png) [@martinlooker](https://www.ruby-forum.com/u/martinlooker)\
**Post date:** [April 4, 2007, 3:02pm UTC](https://www.ruby-forum.com/t/newbie-help-adding-own-actions-to-restful-controllers-to-c/91083/1 "2007-04-04T15:02:12Z")

</div>

Firstly I’m just getting started with rails and am looking to work the  
RESTful way, While the info in Agile Web D. with Rails is  
helpful it is not fully describing what I am trying to achieve which  
is…

I want to set up Accounts with multiple Users, the signup form allows  
the Account name to be given and also the login details for the first  
User, that USer will then be able to add further Users to the  
account.

So far I’ve updated the restful\_authentication plugin, (which is set  
up on my Users), such that the signup form includes an Account name  
and an Account record is created correctly, this is done in the create  
action. Of course next I need to allow further users to be created  
under an account, but I’ve now tied the create function in to creating  
an Account as well.

What I think I ought to do is to move the sign up process to the  
Account controller, but leave the resource\_scaffold Account Controller  
actions alone and create my own action(s) to handle the signup  
process. Now this is where I get a little confused the book suggests  
that for custom actions that create resources I should use something  
like:

map.resources :accounts, :new =\> { :signup =\> :post }

resulting in a url of /accounts/new;signup, I assume this is where the  
save would take place, (it is using the POST method after all), which  
jars somewhat with the standard mapping where accounts/new displays  
the form with the GET method whilst accounts with the POST method  
would actually handle the save. Additionally there is no suggested way  
to provide a custom form.

I think providing mappings like:

map.resources :accounts, :new =\> { :signup =\> :get}, :collection =\>  
{ :create\_signup =\> :post}

would be more fitting giving urls of

GET /accounts/new;signup to display the sign up form.  
POST /accounts;create\_signup to create the records in the database.

Ideally I’d also like to reuse :signup for the :collection mapping,  
(for url purposes), whilst specifing a different action as they can’t  
both use a signup action.

Is this possible and more sensible that using :new with the :post  
method, it seems more in keeping with the standard rest urls to me ?

Or should I be doing something totally different like creating a  
Signup rest controller to handle this seperately treating a signup as  
a resource ?

---

<div class="post-metadata">

**Author:** ![martinlooker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/54ee81/32.png) [@martinlooker](https://www.ruby-forum.com/u/martinlooker)\
**Post date:** [April 5, 2007, 10:36am UTC](https://www.ruby-forum.com/t/newbie-help-adding-own-actions-to-restful-controllers-to-c/91083/2 "2007-04-05T10:36:22Z")

</div>

> Or should I be doing something totally different like creating a  
> Signup rest controller to handle this seperately treating a signup as  
> a resource ?

I did the above in the style of the restful\_authentication pluging’s  
sessions controller. Be careful of using Signup for the controller  
however as that clashes with a route of the restful\_authentication  
plugin, though that route becomes redundant when adding an extra  
controller like this.

It would be nice for someone to comment on the legitimacy of using a  
map resource along the lines of:

map.resources :accounts, :collection =\> {:signup =\> :post } # for url  
of /accounts;signup

rather than the suggested:

map.resources :accounts, :new =\> { :signup =\> : post } # for url of  
accounts/new;signup

in keeping with I understand to be the normal REST conventions.
