Devise add authentication to creating a role
-
13-07-2021 - |
Question
I'm using devise and cancan as an authentication solution.
For devise I have added a role attribute, and created a constant ROLES:
#Migration for adding roles
class AddRoleToUsers < ActiveRecord::Migration
def change
add_column :users, :role, :string
end
end
#Users.rb
ROLES = %w[user staff]
I want to add a function to the signup page, such that for a person to create a user with the role "staff" he has to enter a secret key as well (probably like a secret code like "staffsecretkey" in a input text box)
Anyone know of a way?
Thanks in advance.
Solution
You'll have to do two things:
1) Override devise controllers
2) Customise your views
Check devise wiki in github. You should be able to find all the info you need right there. I'm answering you from my BlackBerry so I could no give you more details right now. But if you can't solve this with the answer I gave you. I'll give you a hand later.