Files
grecia/app/models/site_customization/content_block.rb
taitus ecde8c6439 Add lambda to the validations that use model constants
In this way when we need modify the constants model value in the
model/custom folder, adding lambda it will be possible load the new
values.
2022-03-22 15:52:36 +01:00

12 lines
469 B
Ruby

class SiteCustomization::ContentBlock < ApplicationRecord
VALID_BLOCKS = %w[top_links footer subnavigation_left subnavigation_right].freeze
validates :locale, presence: true, inclusion: { in: I18n.available_locales.map(&:to_s) }
validates :name, presence: true, uniqueness: { scope: :locale }, inclusion: { in: ->(*) { VALID_BLOCKS }}
def self.block_for(name, locale)
locale ||= I18n.default_locale
find_by(name: name, locale: locale)&.body
end
end