From 0ece79a8ae48deaf86b684a407508efcb74ce108 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sun, 19 Jul 2015 14:11:44 +0300 Subject: [PATCH 1/2] Scope event operations to the current conference An indirect Conference -> Track -> Proposition -> Event relation exists within the data model. Use it to limit all operations in the Events controller to events, associated with the current conference. --- app/controllers/management/events_controller.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/management/events_controller.rb b/app/controllers/management/events_controller.rb index 6e51681..4138bfd 100644 --- a/app/controllers/management/events_controller.rb +++ b/app/controllers/management/events_controller.rb @@ -2,23 +2,22 @@ module Management class EventsController < ManagementController def index @conference = find_conference - # TODO (2015-07-14) Scoped by conference? Why no conference_id - @events = Event.approved + @events = @conference.events.approved end def show @conference = find_conference - @event = Event.find(params[:id]) + @event = @conference.events.find(params[:id]) end def edit @conference = find_conference - @event = Event.find(params[:id]) + @event = @conference.events.find(params[:id]) end def update @conference = find_conference - @event = Event.find(params[:id]) + @event = @conference.events.find(params[:id]) if @event.update_attributes(event_params) flash[:notice] = 'Event was successfully updated.' @@ -30,7 +29,7 @@ module Management def destroy @conference = find_conference - @event = Event.find(params[:id]) + @event = @conference.events.find(params[:id]) @event.destroy redirect_to action: :index From d381b800c4e9cbb6bf0042ad04387947c93d39a7 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sun, 19 Jul 2015 14:32:25 +0300 Subject: [PATCH 2/2] Add associations to Track and Conference to Event --- app/models/event.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/event.rb b/app/models/event.rb index 2db7f8a..5c73365 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,6 +1,9 @@ class Event < ActiveRecord::Base include Proposable + has_one :track, through: :proposition, source: :proposition_accepting, source_type: Track + has_one :conference, through: :track + validates :title, presence: true validates :length, presence: true, numericality: {only_integer: true, greater_than: 0} validates :abstract, presence: true