I’m trying to set up 2 slightly different signup processes for my User child classes – Member and Partner. I want to make it so:
/users/sign_up signs up a User as a Member (so I have a hidden field in there with the value ‘Member’) and it works like a charm.
But also I want:
/users/partner/sign_up to provide a slightly different form that ascribes them the value ‘Partner’.
I specifically want this achieved with 2 separate URLs, so I can send these different types of user a different link to sign up with.
I’m using Devise for my authentication system.
I’m pretty sure I should generate a separate controller, something like partner_registrations_controller and have it inherit from devise, but I have no idea what code should then go in the controller.
I also think I need to create a new folder ‘partner_registrations’ within the views/users folder, where I would have the specific ‘new.html.erb’ form.
And I finally I know I need to do something with the routes, like:
devise_for :users, :controllers => { :registrations => :registrations } do
get 'users/partner/sign_up', to: 'devise/registrations#new'
end
I’ve read this wiki page on github: https://github.com/plataformatec/devise/wiki/How-To:-Customize-routes-to-user-registration-pages but I’m non the wiser for it.
Any help is greatly appreciated.
I figured it out, so thought I’d post the answer in case anyone else finds it useful in the future:
Routes file:
I created 2 separate controllers for each child class, with basically the same new and create actions as given by devise:
I just replaced ‘Members’ for ‘ContentPartners’ in the controller for the other child class.
I then created 2 new folders in the Views/Users folder – watch out for the gotcha that got me, they have to be pluralized too – so /members and /content_partners. Then in each folder I created a unique ‘new.html.erb’ file.
That’s it.