Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

263 - Modify College.find(:id) calls to account for destroyed colleges #312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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