add roles to admin panel
This commit is contained in:
3
app/admin/roles.rb
Normal file
3
app/admin/roles.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
ActiveAdmin.register Role do
|
||||
permit_params :name
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
ActiveAdmin.register User do
|
||||
permit_params :email, :name
|
||||
permit_params :email, :name, role_ids: []
|
||||
|
||||
index do
|
||||
selectable_column
|
||||
@@ -17,7 +17,8 @@ ActiveAdmin.register User do
|
||||
form do |f|
|
||||
f.inputs do
|
||||
f.input :email
|
||||
f.input :email
|
||||
f.input :name
|
||||
f.input :roles, as: :check_boxes
|
||||
end
|
||||
f.actions
|
||||
end
|
||||
|
||||
18
app/models/role.rb
Normal file
18
app/models/role.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: roles
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# name :string
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_roles_on_name (name) UNIQUE
|
||||
#
|
||||
class Role < ApplicationRecord
|
||||
has_and_belongs_to_many :users
|
||||
|
||||
validates :name, presence: true, uniqueness: true
|
||||
end
|
||||
@@ -26,5 +26,7 @@ class User < ApplicationRecord
|
||||
:omniauthable,
|
||||
omniauth_providers: [:google_oauth2]
|
||||
|
||||
has_and_belongs_to_many :roles
|
||||
|
||||
validates :name, presence: true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user