Class: Protege::AgentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/protege/agents_controller.rb

Overview

Manages agent records — listing, creating, viewing, editing, and permanent deletion.

An agent is the identity behind an inbox; the controller surfaces the full CRUD the dashboard needs. destroy is the hard, irreversible removal (cascading all the agent's data); the reversible, history-preserving alternative is archiving — see ArchivesController.

Instance Method Summary collapse

Instance Method Details

#createvoid

This method returns an undefined value.

Create an agent from the form's split email fields. Serves POST /agents.

On failure, re-render the form with validation errors.



41
42
43
44
45
46
47
48
49
# File 'app/controllers/protege/agents_controller.rb', line 41

def create
  @agent = Agent.new(create_params)

  if @agent.save
    redirect_to agent_path(@agent), notice: 'Agent created.'
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyvoid

This method returns an undefined value.

Permanently delete an agent and everything it owns. Serves DELETE /agents/:id.

This is the hard, irreversible removal (the reversible path is Archive — see ArchivesController): the model cascades the agent's threads, messages, responsibilities, access rules, and tool-use history. BroadcastableAgent removes its sidebar row.



71
72
73
74
75
# File 'app/controllers/protege/agents_controller.rb', line 71

def destroy
  @agent.destroy!

  redirect_to agents_path, notice: 'Agent deleted.'
end

#editvoid

This method returns an undefined value.

Render the form for editing an agent. Serves GET /agents/:id/edit.



34
# File 'app/controllers/protege/agents_controller.rb', line 34

def edit; end

#indexvoid

This method returns an undefined value.

List every agent. Serves GET /agents.



15
16
17
# File 'app/controllers/protege/agents_controller.rb', line 15

def index
  @agents = Agent.all
end

#newvoid

This method returns an undefined value.

Render the form for creating an agent. Serves GET /agents/new.



27
28
29
# File 'app/controllers/protege/agents_controller.rb', line 27

def new
  @agent = Agent.new
end

#showvoid

This method returns an undefined value.

Show a single agent. Serves GET /agents/:id.



22
# File 'app/controllers/protege/agents_controller.rb', line 22

def show; end

#updatevoid

This method returns an undefined value.

Update an existing agent. Serves PATCH /agents/:id.

On failure, re-render the edit form with validation errors.



56
57
58
59
60
61
62
# File 'app/controllers/protege/agents_controller.rb', line 56

def update
  if @agent.update(update_params)
    redirect_to agent_path(@agent), notice: 'Agent updated.'
  else
    render :edit, status: :unprocessable_entity
  end
end