I'm using rails 4.0.2, devise and cancancan. I'm trying to allow an admin to create new users. Admin users are assigned with a boolean field in the users table.
In ability.rb I have the following:
can :manage, :all if user.admin?
Following some of the advise in this question I created a new controller called AdminsController and it looks like so:
class AdminsController < Devise::RegistrationsController
def create
build_resource(sign_up_params)
if resource.save
redirect_to admin_editors_path
else
clean_up_passwords resource
respond_with resource
end
end
def new
build_resource({})
end
end
I've tried to configure the routes as well:
devise_for :users, :skip => [:registrations]
as :user do
get 'user/admin' => 'admins#new'
post 'user/admin' => 'admins#create'
get 'users/edit' => 'devise/registrations#edit', :as => :edit_user_registration
post 'users/' => 'devise/registrations#create', :as => :user_registration
get 'users/cancel' => 'devise/registrations#cancel', :as => :cancel_user_registration
end
In devise/registrations/edit.html I'm trying to add a link to allow the user to create a new user like so:
<%= link_to "Create User", user_admin_path %>
The problem is that that link just redirects me to the home page with the message
You are already signed in.
I'm not really sure what I'm getting wrong here so any help at all would be much appreciated.