Class: DateBook::EventsController

Inherits:
DateBookController show all
Defined in:
app/controllers/date_book/events_controller.rb

Overview

Allows viewing and maintaining Events within Calendars

Instance Method Summary collapse

Instance Method Details

#createObject

POST /events



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/date_book/events_controller.rb', line 37

def create
  @event.owners = [current_user]
  unless @event.save
    flash[:error] = @event.errors.full_messages.to_sentence
    render :new
    return
  end
  redirect_to([@calendar, @event], notice: :item_acted_on.l(
    item: Event.model_name.human,
    action: :created.l
  ))
end

#destroyObject

DELETE /events/slug



64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/date_book/events_controller.rb', line 64

def destroy
  @event.destroy
  redirect_to(
    calendar_events_url(@calendar),
    notice: :item_acted_on.l(
      item: Event.model_name.human,
      action: :destroyed.l
    )
  )
end

#editObject

GET /events/slug/edit



34
# File 'app/controllers/date_book/events_controller.rb', line 34

def edit; end

#indexObject

GET /events



11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/date_book/events_controller.rb', line 11

def index
  start_date = params[:start]&.to_datetime || Time
               .now
               .beginning_of_month
  end_date   = params[:end]&.to_datetime || Time
               .now
               .beginning_of_month
               .next_month
  @events = @events&.ending_after(start_date)&.starting_before(end_date)
end

#newObject

GET /events/new



31
# File 'app/controllers/date_book/events_controller.rb', line 31

def new; end

#popoverObject

GET /events/slug/popover



26
27
28
# File 'app/controllers/date_book/events_controller.rb', line 26

def popover
  render layout: 'blank'
end

#showObject

GET /events/slug



23
# File 'app/controllers/date_book/events_controller.rb', line 23

def show; end

#updateObject

PATCH/PUT /events/slug



51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/date_book/events_controller.rb', line 51

def update
  unless @event.update(event_params)
    flash[:error] = @event.errors.full_messages.to_sentence
    render :edit
    return
  end
  redirect_to([@calendar, @event], notice: :item_acted_on.l(
    item: Event.model_name.human,
    action: :updated.l
  ))
end