-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
polls_controller.rb
75 lines (59 loc) · 1.63 KB
/
polls_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
class Admin::Poll::PollsController < Admin::Poll::BaseController
include Translatable
include ImageAttributes
include ReportAttributes
load_and_authorize_resource
before_action :load_geozones, only: [:new, :create, :edit, :update]
def index
@polls = @polls.not_budget.created_by_admin.order(starts_at: :desc)
end
def show
end
def new
end
def create
@poll.author = current_user
if @poll.save
notice = t("flash.actions.create.poll")
if @poll.budget.present?
redirect_to admin_poll_booth_assignments_path(@poll), notice: notice
else
redirect_to [:admin, @poll], notice: notice
end
else
render :new
end
end
def edit
end
def update
if @poll.update(poll_params)
redirect_to [:admin, @poll], notice: t("flash.actions.update.poll")
else
render :edit
end
end
def booth_assignments
@polls = Poll.current.created_by_admin
end
def destroy
if ::Poll::Voter.where(poll: @poll).any?
redirect_to admin_poll_path(@poll), alert: t("admin.polls.destroy.unable_notice")
else
@poll.destroy!
redirect_to admin_polls_path, notice: t("admin.polls.destroy.success_notice")
end
end
private
def load_geozones
@geozones = Geozone.order(:name)
end
def poll_params
params.require(:poll).permit(allowed_params)
end
def allowed_params
attributes = [:name, :starts_at, :ends_at, :geozone_restricted, :budget_id, :related_sdg_list,
geozone_ids: [], image_attributes: image_attributes]
[*attributes, *report_attributes, translation_params(Poll)]
end
end