From 2085d8aecbfb095bbf9989a56dd74dc89f1d2a3e Mon Sep 17 00:00:00 2001 From: mo khan Date: Tue, 3 Feb 2015 21:30:13 -0700 Subject: add association from agents to events. --- app/controllers/events_controller.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'app/controllers/events_controller.rb') diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 96a51f0..6a8fe42 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,4 +1,6 @@ class EventsController < ApplicationController + before_action :load_agent + def index @events = Event.all end @@ -8,8 +10,8 @@ class EventsController < ApplicationController end def create - Publisher.publish("events", event_params) - redirect_to events_path, notice: 'Event was successfully created.' + Publisher.publish("events", event_params.merge({agent_id: @agent.id})) + redirect_to agent_events_path, notice: 'Event was successfully created.' end def destroy @@ -18,7 +20,13 @@ class EventsController < ApplicationController 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 -- cgit v1.2.3