-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmake_live_controller.rb
More file actions
39 lines (31 loc) · 1.36 KB
/
make_live_controller.rb
File metadata and controls
39 lines (31 loc) · 1.36 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
module Forms
class MakeLiveController < FormsController
def new
authorize current_form, :can_make_form_live?
@make_live_input = MakeLiveInput.new(form: current_form)
render_new
end
def create
authorize current_form, :can_make_form_live?
@make_live_input = MakeLiveInput.new(**make_live_input_params)
return render_new(status: :unprocessable_content) unless @make_live_input.valid?
return redirect_to form_path(@make_live_input.form.id) unless @make_live_input.confirmed?
@make_form_live_service = MakeFormLiveService.call(current_form:, current_user:)
@make_form_live_service.make_live unless current_form.live?
render "confirmation", locals: { current_form:, confirmation_page_title: @make_form_live_service.page_title, confirmation_page_body: @make_form_live_service.confirmation_page_body }
end
private
def make_live_input_params
params.require(:forms_make_live_input).permit(:confirm).merge(form: current_form)
end
def render_new(status: :ok)
if current_form.is_live?
render "make_your_changes_live", status:, locals: { current_form: }
elsif current_form.is_archived?
render "make_archived_draft_live", status:, locals: { current_form: }
else
render "make_your_form_live", status:, locals: { current_form: }
end
end
end
end