A different registration process with dev / cancan, but only for one user model?

I have so far unsuccessfully trying to use the program to allow two different registration paths to the same user model.

My user model is associated with a different data model, but it does not concern me during registration. But I still want to "show" the difference for users (URL, appearance, etc.), Plus, of course, I want to save a user type in the user model, which is my user so that I can return to a later one and ask what I need to fill out my other models (user related).

I explored the road by rewriting my own registration controller, but I don’t see how this will help with the routes ... I would like something like: / usertype1 / signup and / usertype 2 / signup for more than 2 types of users, but in the end, he should just create the simplest user mode (email, pwd, confirmation, user type).

Any suggestion is welcome at this point :)

Alex

+4
source share
1 answer

In the end, I had to configure custom routes on the same registration page:

devise_for :users, :controllers => { :registrations => "registrations" } do get '/author/sign_up', :to => 'registrations#new' get '/client/sign_up', :to => 'registrations#new' end 

Then, on the registration page, I simply add a hidden field whose value I change depending on the URL:

 - if request.fullpath =~ /\/author\/sign_up/ - session[:registration] = "author" = render 'author' - elsif request.fullpath =~ /\/client\/sign_up/ - session[:registration] = "client" = render 'client' ' 

So, I can visualize 2 pages at registration. This can work with X different types of users.

Alex

+6
source

Source: https://habr.com/ru/post/1336407/


All Articles