I've seen similar posts already, but couldn't quite get the answer I needed.
I have a User model and using STI a Student model that is a type of User.
When I create a new Student, Devise logs in that Student with a student_session. The problem is the rest of my app uses a user_session. SO, should I create a new user_session using the student_session? and then logout the student?
Or is there a way to get Devise to allow a student creation, but login as the User base model?
Thank you, Anthony
Check out this post and see if it helps you:
Rails: Using Devise with single table inheritance
The summary is essentially to do the following:
config/routes.rb:
devise_for :users, :controllers => { :sessions => 'sessions' }, :skip => :registrations
devise_for :students, :skip => :sessions
app/controllers/sessions_controller.rb:
class SessionsController < Devise::SessionsController
def create
rtn = super
sign_in(resource.type.underscore, resource.type.constantize.send(:find, resource.id)) unless resource.type.nil?
rtn
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With