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 ?