diff options
| author | mo khan <mo@mokhan.ca> | 2015-02-03 21:30:13 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-02-03 21:30:13 -0700 |
| commit | 2085d8aecbfb095bbf9989a56dd74dc89f1d2a3e (patch) | |
| tree | 45ab2811e6eb29364dfb526e21727735bbd7e11b /app/controllers/events_controller.rb | |
| parent | bab5e66e261774700eb3ad515eb929fc85991a69 (diff) | |
add association from agents to events.
Diffstat (limited to 'app/controllers/events_controller.rb')
| -rw-r--r-- | app/controllers/events_controller.rb | 12 |
1 files changed, 10 insertions, 2 deletions
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 |
