9

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

0

2 Answers 2

2

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
0

For this you have to create a custom controller. Just an example implementation

#POST create
def create
  student = Student.create(params[:student]) # normal crud with whatever your form params
  sign_in(User.find(student.id)) # this actually signs in the user
  # now redirect the student to the dash board / whatever page manually
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.