-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcopy_of_answers_controller.rb
More file actions
49 lines (36 loc) · 1.72 KB
/
copy_of_answers_controller.rb
File metadata and controls
49 lines (36 loc) · 1.72 KB
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
module Forms
class CopyOfAnswersController < BaseController
before_action :redirect_if_feature_disabled
def show
return redirect_to form_page_path(current_context.form.id, current_context.form.form_slug, current_context.next_page_slug) unless can_visit_copy_of_answers?
@back_link = back_link
@copy_of_answers_input = CopyOfAnswersInput.new
end
def save
@copy_of_answers_input = CopyOfAnswersInput.new(copy_of_answers_params)
unless @copy_of_answers_input.valid?
@back_link = back_link
return render :show, status: :unprocessable_content
end
current_context.save_copy_of_answers_preference(@copy_of_answers_input.wants_copy?)
redirect_to check_your_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
end
private
def copy_of_answers_params
params.require(:copy_of_answers_input).permit(:copy_of_answers)
end
def can_visit_copy_of_answers?
current_context.can_visit?(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)
end
def back_link
previous_step = current_context.previous_step(CheckYourAnswersStep::CHECK_YOUR_ANSWERS_PAGE_SLUG)
if previous_step.present?
previous_step.repeatable? ? add_another_answer_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug, page_slug: previous_step.id) : form_page_path(current_context.form.id, current_context.form.form_slug, previous_step.id)
end
end
def redirect_if_feature_disabled
return if FeatureService.enabled?("filler_answer_email_enabled")
redirect_to check_your_answers_path(form_id: current_context.form.id, form_slug: current_context.form.form_slug)
end
end
end