Class: EgovUtils::RolesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/egov_utils/roles_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/egov_utils/roles_controller.rb', line 12

def create
  entity = params[:entity_class].safe_constantize.try(:find, params[:id])
  return render_404 unless entity
  authorize! :manage, entity
  entity.roles = params[:roles].map(&:presence).compact if params[:roles].is_a?(Array)
  if entity.save
    respond_to do |format|
      format.json { render json: entity.roles }
    end
  else
    respond_to do |format|
      format.json { render json: entity.errors.full_messages, status: :unprocessable_entity }
    end
  end
end

#indexObject



5
6
7
8
9
10
# File 'app/controllers/egov_utils/roles_controller.rb', line 5

def index
  authorize! :manage, User
  authorize! :manage, Group
  @users = User.all
  @groups = Group.all
end