Can't override Devise::RegistrationsController in Rails?

Viewed 169

I'm trying to set a default behaviour after User sign in and sign up.

I've tried creating a registration_controller.rb with the following code:

class RegistrationsController < Devise::RegistrationsController

  protected


  def after_sign_up_path_for(resource)
    "/projects"
  end

  def after_sign_in_path_for(resource)
    raise
    "/projects"
  end

end

which doesn't even get me to the raise

As a workaround I've managed to make it work creating a method in application_controller.rb as follows:

  def after_sign_in_path_for(resource)
    "/projects"
  end

but I would like to know why I wasn't overriding the default RegistrationsController class.

1 Answers

According to Devise documentation, you can customize its configuration by running rails generate devise:controllers [scope], replacing scope by users for example.

Then it generates files like this:

class Users::RegistrationsController < Devise::RegistrationsController
  # GET /resource/sign_in
  # def new
  #   super
  # end
  ...
end

You can uncomment the methods you need and write your code after super.

Related