Browse Source

Linting

pull/41/head
baarkerlounger 3 years ago
parent
commit
541b850015
  1. 2
      app/controllers/case_logs_controller.rb
  2. 4
      app/models/case_log.rb

2
app/controllers/case_logs_controller.rb

@ -45,7 +45,7 @@ class CaseLogsController < ApplicationController
form = Form.new(2021, 2022)
form.all_pages.map do |page_key, page_info|
define_method(page_key) do |errors = {}|
define_method(page_key) do |_errors = {}|
@case_log = CaseLog.find(params[:case_log_id])
render "form/page", locals: { form: form, page_key: page_key, page_info: page_info }
end

4
app/models/case_log.rb

@ -1,5 +1,4 @@
class CaseLogValidator < ActiveModel::Validator
# Methods need to be named 'validate_' followed by field name
# this is how the metaprogramming of the method name being
# call in the validate method works.
@ -13,7 +12,7 @@ class CaseLogValidator < ActiveModel::Validator
def validate_tenant_age(record)
if record.tenant_age.blank?
record.errors.add :tenant_age, "Tenant age can't be blank"
elsif !(record.tenant_age.to_s =~ /^[1-9][0-9]?$|^100$/)
elsif !/^[1-9][0-9]?$|^100$/.match?(record.tenant_age.to_s)
record.errors.add :tenant_age, "Tenant age must be between 0 and 100"
end
end
@ -29,6 +28,7 @@ end
class CaseLog < ApplicationRecord
validate :instance_validations
attr_writer :previous_page
enum status: { "in progress" => 0, "submitted" => 1 }
def instance_validations

Loading…
Cancel
Save