Skip to content

Commit

Permalink
Avoid the need to add a custom error in new Claims::School controller…
Browse files Browse the repository at this point in the history
… logic
  • Loading branch information
Nitemaeric committed Jan 5, 2024
1 parent d1f01d9 commit f9263eb
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions app/controllers/claims/support/schools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ def new
end

def check
if school.valid? && !school.claims?
if school.valid?
@school = school.decorate
else
school.errors.add(:urn, :taken) if school.claims?
render :new
end
end

def create
school.claims = true
if school.save
if school.update(claims: true)
redirect_to claims_support_schools_path
else
render :new
Expand All @@ -32,15 +30,11 @@ def create
private

def school
@school ||=
begin
gias_school = GiasSchool.find_by(urn: urn_param)
if gias_school.blank?
Claims::School.new
else
gias_school.school || gias_school.build_school
end
end
@school ||= School.find_by(gias_school:, claims: false) || Claims::School.new(gias_school:)
end

def gias_school
@gias_school ||= GiasSchool.find_by(urn: urn_param)
end

def urn_param
Expand Down

0 comments on commit f9263eb

Please sign in to comment.