Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Superclass mismatch for class RegistrationController - Overriding Devise Controller

I am trying to override my devise registration controller, with no luck.

I finally got the routes working, but now I'm getting an superclass mismatch for class error.

Heres my setup:

Registration Controller (app/controllers/users/registrations_controller.rb)

class RegistrationsController < Devise::RegistrationsController

  def sign_up_params
    devise_parameter_sanitizer.sanitize(:sign_up)
    params.require(:user).permit(:email, :password, profile_attributes: [:username])
  end

  def new
    super
  end

  def create

  end

  def update
    super
  end

end

Routes

root 'welcome#index'

devise_for :users, :controllers => {:registrations => "users/registrations"}

Views

--edit.html.erb && new.html.erb exist in the folder (app/views/users/registrations)

User Model (just in case)

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  has_one :profile
  accepts_nested_attributes_for :profile

  def profile
    super || build_profile
  end

end

Any idea why this error is appearing?

Thanks!

like image 206
Ricky Mason Avatar asked Dec 06 '22 03:12

Ricky Mason


1 Answers

Your controller is underneath the users directory but does not have a Users module (it is not in the Users namespace, you might say). Either change the controller to this:

module Users
  class RegistrationsController < Devise::RegistrationsController
  ...
  end
end

Or move your controller up a directory

app/controllers/registrations_controller.rb

like image 107
WattsInABox Avatar answered May 08 '23 09:05

WattsInABox