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
     |