I'm using Devise for student authentication and I have other actions called show_profile and edit_profile so a student can see and edit his profile.

The problem is the controller I made over writes the Devise controllers so the sign in/up stops working. How can I make my controller an extension for the Devise controllers?

If I put those two:

class Students::RegistrationsController < Devise::RegistrationsController
class StudentsController < ApplicationController

and comment this when logging in class StudentsController < ApplicationController and this class Students::RegistrationsController < Devise::RegistrationsController after login it works.

class Students::RegistrationsController < Devise::RegistrationsController
#class StudentsController < ApplicationController

     private
    def secure_params
      params.require(:student).permit(:name, :father_name, :grand_father_name)
    end
   public
     before_action :authenticate_student!
   def show_profile
        @student = current_student
     end

   def edit_profile
        @student = current_student
   end

   def update_profile
   @student = current_student

    if @student.update_attributes(secure_params)
      redirect_to(:action => 'show_profile',:id => @student.id )
      flash[:notice] = "student edited successfully"
    else
      render('edit_profile')
    end
   end
end

1 Answers

0
Iceman On

You have to tell Devise that you're using a custom setup in your routes.rb Something like this, tweak to your needs.

devise_for :users,
  controllers: {
    registrations: 'student/registrations'
  }

Use devise_for :students obviously if that's what your model is called.