class Eventable::OpeningPeriodsController < Eventable::EventableController before_filter :get_event before_filter :get_opening_periods, :only => [:index] before_filter :get_opening_period, :only => [:show, :edit, :update, :destroy] before_filter :new_opening_period, :only => [:new, :create] def create if @opening_period.update_attributes(params[:eventable_opening_period]) try_after_callback do flash[:notice] = 'Opening Period was successfully added.' redirect_to (if params[:list] eventable_event_opening_periodlist_path @event else eventable_event_opening_period_path @event, @opening_period end) end else try_after_callback :fail do render :action => "new" end end end def update if @opening_period.update_attributes(params[:eventable_opening_period]) try_after_callback do flash[:notice] = 'Opening period was successfully updated.' redirect_to (if params[:list] eventable_event_opening_periodlist_path @event else eventable_event_opening_period_path @event, @opening_period end) end else try_after_callback :fail do render :action => "edit" end end end def destroy @opening_period.destroy try_after_callback do redirect_to (if params[:list] eventable_event_opening_periodlist_path @event else eventable_event_opening_periods_path @event end) end end private def model @event ? @event.opening_periods : Eventable::OpeningPeriod end def get_opening_periods @opening_periods = model.all end def get_opening_period @opening_period = model.find(params[:id]) @event ||= @opening_period.event #fix @event in case we aren't #below /events end def new_opening_period @opening_period = @event ? model.build : model.new end def get_event @event = event_model.find(params[:event_id]) if params[:event_id] end end