Browse Source

Attr writter added

pull/39/head
Matthew Phelan 3 years ago
parent
commit
dc3e13cbb0
  1. 2
      app/controllers/case_logs_controller.rb
  2. 6
      app/models/case_log.rb

2
app/controllers/case_logs_controller.rb

@ -26,7 +26,7 @@ class CaseLogsController < ApplicationController
previous_page = params[:case_log][:previous_page]
questions_for_page = form.questions_for_page(previous_page).keys
answers_for_page = page_params(questions_for_page).select { |k, _v| questions_for_page.include?(k) }
@case_log.previous_page(previous_page)
@case_log.previous_page = previous_page
if @case_log.update(answers_for_page)
redirect_path = form.next_page_redirect_path(previous_page)
redirect_to(send(redirect_path, @case_log))

6
app/models/case_log.rb

@ -28,13 +28,9 @@ end
class CaseLog < ApplicationRecord
validate :instance_validations
@previous_page
attr_writer :previous_page
enum status: { "in progress" => 0, "submitted" => 1 }
def previous_page(value)
@previous_page = value
end
def instance_validations
validates_with CaseLogValidator, ({ previous_page: @previous_page } || {})
end

Loading…
Cancel
Save