When modeling my application I have two types of users that have a polymorphic association to the user model. Such as:
1 2 3 4 5 6 7 8 9 10 11 | |
The reason I did this, instead of an STI, is because User_Type_1 has something like 4 fields and User_Type_2 has something like 20 fields and I didn’t want the user table to have so many fields (yes 24-ish fields is not a lot but I’d rather not have ~20 fields empty most of the time)
The problem I was facing at this point was I want the sign up form to only be used to sign up users of type User_Type_1 but the sign in form to be used to both. (I will have an admin side of the application which will create users of User_Type_2)
I knew I can use the after_sign_in_path_for(resource) override in AppicationController somehow to redirect to the right part of the site on sign in. Something like:
1 2 3 4 5 6 7 8 | |
To achieve what I wanted here I just created a normal form for the User_Type_1 with nested attributes for User and had it post to the UserType1Controller:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
Then saved both objects and called the sign_in_and_redirect helper from Devise
1 2 3 4 5 6 7 8 9 10 11 12 | |
Then the after_sign_in_path_for method from above sent it to the right place and it was all good.