Sha256: 673a3d0e17c161eb824f0c985a1626b8aff1964b5d56d607af4b3b8a26cda7a5

Contents?: true

Size: 2 KB

Versions: 3

Compression:

Stored size: 2 KB

Contents

module Qcourses
  class EventsController < BaseController
    resource '/events'

    get request_url do
      begin
        CourseRepository.all
        @events = Event.planned
        haml :'events/index', layout: false
      rescue Exception => e
        haml :'trainings/error', locals: { message: e.message } 
      end
    end

    get admin_request_url do
      begin
        CourseRepository.all
        @events = Event.order(:from)
        haml :'events/admin_index', layout: :admin
      rescue Exception => e
        haml :'trainings/error', locals: { message: e.message } 
      end
    end

    get admin_new_request_url do
      begin
        @event = Event.new
        @events = Event.order(:from)
        haml :'events/new', layout: :admin
      rescue Exception => e
        haml :'trainings/error', locals: { message: e.message } 
      end
    end

    get admin_edit_request_url(:id) do
      begin
        @event = Event.find(params[:id])
        haml :'events/edit', layout: :admin
      rescue Exception => e
        haml :'trainings/error', locals: { message: e.message } 
      end
    end

    post admin_request_url do
      @event = Event.create(event_params)
      redirect admin_new_request_url
    end

    put admin_request_url(:id) do
      @event = Event.find(params[:id])
      begin
        @event.update event_params
        redirect admin_request_url
      rescue ValidationFailed
        haml :'events/edit', layout: :admin
      rescue Exception => e
        haml :'trainings/error', locals: { message: e.message } 
      end
    end
    
    private 
    def event_params
      @event_params ||= filter_event_params
    end
    def filter_event_params
      result = params[:event]
      valid_parameters = ["course_id", "from", "to", "location", "max_participants"]
      if (result[:location_id] && result[:location_id] != '0')
        valid_parameters << "location_id"
        valid_parameters.delete 'location'
      end
      result.select {|key| valid_parameters.include?(key)}
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qcourses-0.1.11 lib/qcourses/controllers/events_controller.rb
qcourses-0.1.10 lib/qcourses/controllers/events_controller.rb
qcourses-0.1.9 lib/qcourses/controllers/events_controller.rb