forked from metaskills/757studio
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsvps_controller.rb
105 lines (84 loc) · 2.25 KB
/
rsvps_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
class RsvpsController < ApplicationController
before_filter :admin_required, :except => [:create,:clear,:mine,:toggle_reservation]
rescue_from ActiveRecord::RecordNotFound, :with => :not_found
def index
@rsvps = Rsvp.all
end
def create
self.current_rsvp = Rsvp.create!(params[:rsvp])
head :ok
end
def destroy
find_rsvp_id
@rsvp.destroy
flash[:good] = "Succesfully destroyed RSVP for #{@rsvp.name} with email of <#{@rsvp.email}>."
redirect_to rsvps_url
end
def edit
find_rsvp_id
end
def update
find_rsvp_id
begin
update_rsvp_attributes
redirect_to edit_rsvp_url(@rsvp)
rescue ActiveRecord::RecordInvalid
render :action => 'edit'
end
end
def clear
clear_rsvp
redirect_to root_path
end
def mine
find_by_slug
if request.get?
clear_rsvp
@rsvp.reserved! unless session[:toggled_reservation]
elsif request.put?
begin
update_rsvp_attributes
redirect_to mine_rsvp_url(:id => @rsvp.slug)
rescue ActiveRecord::RecordInvalid
render
end
end
end
def toggle_reservation
find_by_slug
session[:toggled_reservation] = true
@rsvp.toggle(:reserved).save!
redirect_to mine_rsvp_url(:id => @rsvp.slug)
rescue ActiveRecord::RecordInvalid
render :action => 'mine'
end
def send_reminders
reminded = Rsvp.send_reminders
reminded_notice = reminded.map { |rsvp| "#{rsvp.name} at #{rsvp.email}" }
flash[:good] = "Sent reminders out to the following: #{reminded_notice.to_sentence}"
redirect_to rsvps_url
end
def send_upcoming_reminders
RsvpMailer.deliver_upcoming_event_reminders
flash[:good] = "Sent upcoming event reminders to #{Rsvp.count} people."
redirect_to rsvps_url
end
protected
def find_rsvp_id
@rsvp = Rsvp.find(params[:id])
end
def find_by_slug
@rsvp = Rsvp.find_by_slug!(params[:id])
end
def update_rsvp_attributes
@rsvp.update_attributes!(params[:rsvp])
flash[:good] = 'Successfully updated reservation and attendee information.'
end
def not_found
flash[:bad] = 'Reservation was not found.'
redirect_to root_path
end
def clear_rsvp
self.current_rsvp = nil
end
end