martinlooker
2007-Apr-04 12:48 UTC
(Newbie) Help adding own actions to restful controllers to create records
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 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 ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
martinlooker
2007-Apr-05 08:34 UTC
Re: (Newbie) Help adding own actions to restful controllers to create records
> 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. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---