Browse Source

DRY up partials

pull/26/head
baarkerlounger 3 years ago
parent
commit
1be3ce0c60
  1. 13
      app/controllers/case_logs_controller.rb
  2. 2
      app/views/form/_checkbox_question.html.erb
  3. 2
      app/views/form/_date_question.html.erb
  4. 2
      app/views/form/_numeric_question.html.erb
  5. 3
      app/views/form/_radio_question.html.erb
  6. 2
      app/views/form/_text_question.html.erb
  7. 6
      app/views/form/page.html.erb

13
app/controllers/case_logs_controller.rb

@ -1,4 +1,5 @@
class CaseLogsController < ApplicationController
def index
@submitted_case_logs = CaseLog.where(status: 1)
@in_progress_case_logs = CaseLog.where(status: 0)
@ -17,7 +18,7 @@ class CaseLogsController < ApplicationController
def edit
@form = Form.new(2021, 2022)
@case_log = CaseLog.find(params[:id])
render :edit, locals: { form: @form }
render :edit
end
def next_page
@ -31,10 +32,6 @@ class CaseLogsController < ApplicationController
redirect_to(send("case_log_#{next_page}_path", @case_log))
end
def page_params(questions_for_page)
params.permit(questions_for_page)
end
form = Form.new(2021, 2022)
form.all_pages.map do |page_key, page_info|
define_method(page_key) do
@ -42,4 +39,10 @@ class CaseLogsController < ApplicationController
render "form/page", locals: { case_log_id: @case_log.id, form: form, page_key: page_key, page_info: page_info }
end
end
private
def page_params(questions_for_page)
params.permit(questions_for_page)
end
end

2
app/views/form/_checkbox_question.html.erb

@ -12,4 +12,4 @@
<% end %>
<%= f.hidden_field :previous_page, value: page_key %>
<%= f.hidden_field :case_log_id, value: case_log_id %>
<%= f.hidden_field :case_log_id, value: case_log.id %>

2
app/views/form/_date_question.html.erb

@ -3,5 +3,3 @@
legend: { text: question["header"], size: "l"},
width: 20
%>
<%= f.hidden_field :previous_page, value: page_key %>
<%= f.hidden_field :case_log_id, value: case_log_id %>

2
app/views/form/_numeric_question.html.erb

@ -3,5 +3,3 @@
label: { text: question["header"], size: "l"},
min: question["min"], max: question["max"], step: question["step"], width: 20
%>
<%= f.hidden_field :previous_page, value: page_key %>
<%= f.hidden_field :case_log_id, value: case_log_id %>

3
app/views/form/_radio_question.html.erb

@ -11,6 +11,3 @@
<% end %>
<% end %>
<% end %>
<%= f.hidden_field :previous_page, value: page_key %>
<%= f.hidden_field :case_log_id, value: case_log_id %>

2
app/views/form/_text_question.html.erb

@ -3,5 +3,3 @@
label: { text: question["header"], size: "l"},
width: 20
%>
<%= f.hidden_field :previous_page, value: page_key %>
<%= f.hidden_field :case_log_id, value: case_log_id %>

6
app/views/form/page.html.erb

@ -12,9 +12,13 @@
</h1>
<% end %>
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<% page_info["questions"].map do |question_key, question| %>
<%= render partial: "form/#{question["type"]}_question", locals: { case_log_id: case_log_id, page_key: page_key, question_key: question_key, question: question, f: f } %>
<%= render partial: "form/#{question["type"]}_question", locals: { question_key: question_key, question: question, f: f } %>
<% end %>
<%= f.hidden_field :previous_page, value: page_key %>
<%= f.hidden_field :case_log_id, value: case_log_id %>
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>

Loading…
Cancel
Save