Skip to content

Commit

Permalink
Merge pull request #312 from uclibs/bug-263-citations-page-crashing-a…
Browse files Browse the repository at this point in the history
…fter-college-deletion

263 - Modify College.find(:id) calls to account for destroyed colleges
  • Loading branch information
Janell-Huyck authored Nov 28, 2023
2 parents 2acab86 + 7fbf7e5 commit 5dad942
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/colleges_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def destroy

# Use callbacks to share common setup or constraints between actions.
def set_college
@college = College.find(params[:id])
@college = College.find_by(id: params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
Expand Down
6 changes: 1 addition & 5 deletions app/helpers/colleges_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ def check_other_college(publication)
end

def college_name(id)
if id.nil?
''
else
College.find(id).name
end
College.name_for(id)
end

def college_array(publication)
Expand Down
7 changes: 7 additions & 0 deletions app/models/college.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ class College < ApplicationRecord
has_and_belongs_to_many :books, dependent: :destroy
has_and_belongs_to_many :other_publications, dependent: :destroy
validates :name, presence: true

def self.name_for(id)
return '' if id.nil?

college = College.find_by(id:)
college&.name.to_s
end
end
6 changes: 1 addition & 5 deletions app/models/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ def author_name(position)
end

def college_name(id)
if id.nil?
''
else
College.find(id).name
end
College.name_for(id)
end

def colleges
Expand Down

0 comments on commit 5dad942

Please sign in to comment.