Sha256: 4547ea84f54d8d4290cb66ff8970abda8c2f6cd5771af4fc0398640321ec0a9c
Contents?: true
Size: 1.38 KB
Versions: 8
Compression:
Stored size: 1.38 KB
Contents
class AgentsController < AdminController before_action :set_entity, only: [:edit, :update, :destroy] before_action :restrict_editing, only: [:edit, :update, :destroy] # get /agents/new def new @entity = Agent.new end # post /agents def create @entity = Agent.new entity_parameters if @entity.save redirect_to admin_agent_path(id: @entity.id) else render :new, status: :bad_request end end # get /agents/:id def show end # get /agents/:id/edit def edit end # patch /agents/:id def update if @entity.update entity_parameters redirect_to admin_agent_path(id: @entity.id), notice: t('agents.update.success') else render :edit, status: :bad_request end end # delete /agents/:id def destroy if @entity.update! deleted: true flash[:notice] = t('agents.destroy.success') end redirect_to admin_agents_path end private def restrict_access require_privilege :administrator end def set_entity @entity = Agent.find_by(id: params[:id], deleted: false) if @entity.nil? handle_http_404('Agent is not found or was deleted') end end def restrict_editing if @entity.locked? redirect_to admin_agent_path(id: @entity.id), alert: t('agents.edit.forbidden') end end def entity_parameters params.require(:agent).permit(Agent.entity_parameters) end end
Version data entries
8 entries across 8 versions & 1 rubygems