Since targets didn't have a title but only a long description, every form allowing to select targets was pretty much unusable: we either displayed just the code or the whole description. Now, with a concise title, it's easier to find and select the desired target. The titles have been copied from The Global Goals page [1]. Note we're using the `short_title` I18n key for the `title` method and the `long_title` I18n key for the `long_title` method. We can't use `title` as I18n key instead of `short_title` because it would affect existing translations. [1] https://www.globalgoals.org/
26 lines
542 B
Ruby
26 lines
542 B
Ruby
class SDG::Goal < ApplicationRecord
|
|
include SDG::Related
|
|
|
|
validates :code, presence: true, uniqueness: true, inclusion: { in: 1..17 }
|
|
|
|
has_many :targets, dependent: :destroy
|
|
has_many :local_targets, dependent: :destroy
|
|
|
|
def title
|
|
I18n.t("sdg.goals.goal_#{code}.title")
|
|
end
|
|
alias_method :long_title, :title
|
|
|
|
def title_in_two_lines
|
|
I18n.t("sdg.goals.goal_#{code}.title_in_two_lines")
|
|
end
|
|
|
|
def description
|
|
I18n.t("sdg.goals.goal_#{code}.description")
|
|
end
|
|
|
|
def self.[](code)
|
|
find_by!(code: code)
|
|
end
|
|
end
|