Browse Source

Linting

pull/41/head
baarkerlounger 3 years ago
parent
commit
541b850015
  1. 2
      app/controllers/case_logs_controller.rb
  2. 8
      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 = Form.new(2021, 2022)
form.all_pages.map do |page_key, page_info| 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]) @case_log = CaseLog.find(params[:case_log_id])
render "form/page", locals: { form: form, page_key: page_key, page_info: page_info } render "form/page", locals: { form: form, page_key: page_key, page_info: page_info }
end end

8
app/models/case_log.rb

@ -1,7 +1,6 @@
class CaseLogValidator < ActiveModel::Validator class CaseLogValidator < ActiveModel::Validator
# Methods need to be named 'validate_' followed by field name # Methods need to be named 'validate_' followed by field name
# this is how the metaprogramming of the method name being # this is how the metaprogramming of the method name being
# call in the validate method works. # call in the validate method works.
def validate_tenant_code(record) def validate_tenant_code(record)
@ -13,7 +12,7 @@ class CaseLogValidator < ActiveModel::Validator
def validate_tenant_age(record) def validate_tenant_age(record)
if record.tenant_age.blank? if record.tenant_age.blank?
record.errors.add :tenant_age, "Tenant age can't be 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" record.errors.add :tenant_age, "Tenant age must be between 0 and 100"
end end
end end
@ -26,9 +25,10 @@ class CaseLogValidator < ActiveModel::Validator
end end
end end
class CaseLog < ApplicationRecord class CaseLog < ApplicationRecord
validate :instance_validations validate :instance_validations
attr_writer :previous_page attr_writer :previous_page
enum status: { "in progress" => 0, "submitted" => 1 } enum status: { "in progress" => 0, "submitted" => 1 }
def instance_validations def instance_validations

Loading…
Cancel
Save