Add method to easily access a goal by code

Similar to what we do with settings, only for settings we return the
value of the setting (which is what we're going to need most of the
time), and here we return the object.
This commit is contained in:
Javi Martín
2020-11-24 19:42:37 +01:00
parent c7c8309ad1
commit d5ee1ff89c
2 changed files with 17 additions and 3 deletions

View File

@@ -8,4 +8,8 @@ class SDG::Goal < ApplicationRecord
def description
I18n.t("sdg.goals.goal_#{code}.description")
end
def self.[](code)
find_by!(code: code)
end
end