Reputation: 2072
In Devise we can restrict user to sign up directly by removing :registerable symbol form User model. But my theme is to create own user sign up page and controller and allow admin to create users manually. I tried many times but the problem is that how to encrypt password so that it becomes accessible by devise during login. If there is any idea please help.
Upvotes: 1
Views: 869
Reputation: 2072
I did this for solving problem
And thank you for effort for helping.
Upvotes: 2
Reputation: 5905
Here are some suggestions and solution:
Don't delete the :regesterable
from User
model. Instead, just define a different route for the registration
in routes.rb
file, so that others cannot find that path to register.
e.g. devise_for :users, path_names: { sign_up: 'register_not_allowed' }
Create a module like Admin
and then define a controller like UsersController
under this module. e.g.
module Admin
class UsersController < ApplicationController
end
end
In the controller
create new, edit, show, create, update methods as you do for any controller. create a form having fields with email
, password
, password_confirmation
and also with the additional fields which is an attribute in User
model. Then require them in the strong parameters of your admin/users
controller. Now when you create an user using this form no encryption of password is needed.
app/views/admin/users/_form.html.erb
<%= form_for [:admin, @user] do |f| %>
<% end %>
Upvotes: 3