3

I realize this has been asked many times on here (I also read through the wiki). But I am still confused at how to properly keep my route names the same.

Currently my devise routes are below, using custom url's (for example /user/signup).

My model is called User

Routes:

  devise_for :users, :controllers => { :registrations => "registrations" }, :path_names => {
    :sign_up => 'signup'
  }

  devise_for :users, :path => "user", :except => "create", :path_names => { 
    :sign_in  => 'login', 
    :sign_out => 'logout', 
    :password => 'forgot-password', 
    :confirmation => 'verification', 
    :unlock   => 'unblock', 
    :sign_up  => 'signup' 
  } 

All I am trying to do is hook into the create action so I can check if a honeypot field I have created is filled out (to prevent spam). That's really all I want to do.

I want to keep my url the same though /user/signup. Is there an extra step I need to do?

This is what I have so far in...

/app/controllers/registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController

  def new
    super
  end

  def create
    super
  end

end   

I am getting uninitialized constant Users

Tallboy
  • 12,847
  • 13
  • 82
  • 173
  • possible duplicate of [devise overriding registrations controller - uninitialized constant Users::RegistrationsController](http://stackoverflow.com/questions/8466822/devise-overriding-registrations-controller-uninitialized-constant-usersregis) – Jonathan Jul 05 '14 at 17:38

4 Answers4

10

Quite simply I needed to put the controller in a 'users' folder, and that fixed everything. (Also, the route controller needs to be :registrations => "users/registrations"

Tallboy
  • 12,847
  • 13
  • 82
  • 173
3

I've had the same error. in my case it was in routes.rb

was: devise_for :users,controllers: {sessions: "users/sessions"}

result: uninitialized constant Users

I had no idea what's going on till {sessions: "users/sessions"} in my case it should be user/sessions without "s"

aforalegria
  • 370
  • 3
  • 9
2

You don't need to name the controller Users::RegistrationsController, just name it RegistrationsController keeping the inheritance from Devise::RegistrationsController.

I don't know the purpose of the first devise_for but you need to copy/move :controllers => { :registrations => "registrations" } to the second devise_for.

Ahmad Sherif
  • 5,923
  • 3
  • 21
  • 27
1

On devise (4.7.3) and rails (6.0.3.3) the correct controller is Session not Sessions.

You need to add this in your config/route.rb

devise_for :users, controllers: { session: 'users/sessions' }
monteirobrena
  • 2,562
  • 1
  • 33
  • 45