Forum: Ruby on Rails (Newbie) Help adding own actions to restful controllers to c

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
1d94db56879170906abf47cd3346d82d?d=identicon&s=25 martinlooker (Guest)
on 2007-04-04 15:02
(Received via mailing list)
Firstly I'm just getting started with rails and am looking to work the
RESTful way, While the info in Agile Web Development with Rails is
helpful it is not fully describing what I am trying to achieve which

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

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

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 ?
1d94db56879170906abf47cd3346d82d?d=identicon&s=25 martinlooker (Guest)
on 2007-04-05 10:36
(Received via mailing list)
> 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

in keeping with I understand to be the normal REST conventions.
This topic is locked and can not be replied to.