Different registration process with devise / cancan but only one User model?
I have being trying unsuccessfully so far to use devise to allow for 开发者_如何学Python2 different path of registration to the same User model.
My user model is linked to other data model, but I don't care about that at registration time. But I still want to "show" the difference to the users (url path, look & feel, etc.) plus of course I want to save in the User model the user type that my user is so I can go back at a later point and ask for what I need to fill in my other models (linked to User).
I have explored the road the rewritte my own registration controller, but I don't see how that is going to help with with the routes... I'd like something like: /usertype1/signup and /usertype2/signup virtually for more than 2 usertypes, but in the end it should just create the simplest User mode (email, pwd, confirmation, usertype).
Any suggestion is welcome at this point :)
Alex
What I did finally is to have to custom routes points to 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 which 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 then render the look of 2 different page on registration. This could work with X different type of users.
Alex
精彩评论