From a0de57bed9208cef5783f8ff35992857829d40c1 Mon Sep 17 00:00:00 2001 From: Matchu Date: Fri, 28 Jul 2023 15:33:46 -0700 Subject: [PATCH] Backfill globalize's find_by_name method This method was removed in globalize 4, which we upgraded to for compatibility with Rails 4! Let's add back in a similar thing for now! --- app/models/color.rb | 6 ++++++ app/models/species.rb | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/app/models/color.rb b/app/models/color.rb index 0732929e..9a2f7662 100644 --- a/app/models/color.rb +++ b/app/models/color.rb @@ -13,6 +13,12 @@ class Color < ActiveRecord::Base } validates :name, presence: true + + # TODO: Should we consider replacing this at call sites? This used to be + # built into the globalize gem but isn't anymore! + def self.find_by_name(name) + matching_name(name).first + end def as_json(options={}) {id: id, name: human_name, unfunny_name: unfunny_human_name, prank: prank?} diff --git a/app/models/species.rb b/app/models/species.rb index 35092aed..7cf4fee0 100644 --- a/app/models/species.rb +++ b/app/models/species.rb @@ -8,6 +8,12 @@ class Species < ActiveRecord::Base joins(:translations).where(st[:locale].eq(locale)). where(st[:name].matches(sanitize_sql_like(name))) } + + # TODO: Should we consider replacing this at call sites? This used to be + # built into the globalize gem but isn't anymore! + def self.find_by_name(name) + matching_name(name).first + end def as_json(options={}) {:id => id, :name => human_name}