summaryrefslogtreecommitdiff
path: root/app/controllers/agents/events_controller.rb
blob: ce66c5b54045380cb75e1f7e38b0195b0acd7cbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Agents
  class EventsController < ApplicationController
    before_action :load_agent

    def index
      @events = Event.all
    end

    def new
      @event = Event.new
    end

    def create
      Publisher.publish("events", event_params.merge({agent_id: @agent.id}))
      redirect_to agent_events_path, notice: 'Event was successfully created.'
    end

    def destroy
      @event = Event.find(params[:id])
      @event.destroy
      redirect_to events_url, notice: 'Event was successfully destroyed.'
    end

    private

    def event_params
      params.require(:event).permit(:name, :data)
    end

    def load_agent
      @agent = Agent.find(params[:agent_id])
    end
  end
end