1

In devise I'm trying to make it so that a Logged in user can create a new user via the Devise signup form.

Currently I've tried overriding the controller but it keeps redirecting me back to the root page due to me being logged in.

registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController
  skip_before_action :require_no_authentication, only: [:new, :create, :cancel]

  protected

  def create
    User.create!({:email => params[:email], :roles => [''], :password => params[:password], :password_confirmation => params[:password_confirmation] })
  end

  def sign_up(resource_name, resource)
  end
end

routes.rb

 devise_for :users, controllers: { registrations: "registrations" }, skip: [:sessions]

Am I missing something obvious, because I assumed the code below would allow it so I could view the form when I'm logged in?

  skip_before_action :require_no_authentication, only: [:new, :create, :cancel]

Solution:

I was being too specific in my signup route it was set as devise/registration#new instead of registrations#new

If anyone reading this in future gets stuck, let me know and i'll try my best to help! :)

RushRed
  • 75
  • 1
  • 12
  • you can visit the following link for your solution http://stackoverflow.com/questions/23140117/allow-a-user-to-add-new-users-in-devise-and-remain-logged-in-as-themselves – Manish Singh Jan 23 '17 at 17:09
  • Possible duplicate of [Allow a user to add new users in Devise, and remain logged in as themselves](http://stackoverflow.com/questions/23140117/allow-a-user-to-add-new-users-in-devise-and-remain-logged-in-as-themselves) – Eyeslandic Jan 23 '17 at 17:14
  • @Manish My routes are correct, which seemed to be the issue in that question. – RushRed Jan 23 '17 at 17:18
  • @Iceman I read that post, it didn't seem to fix my issue as my routes were correct – RushRed Jan 23 '17 at 17:19
  • Don't use RegistrationsController for this purpose. You better create your own action, for example `UsersController#create`. This will give you more control and avoid problems. – chumakoff Jan 23 '17 at 19:58

0 Answers0