Skip to content

Commit 96a32cc

Browse files
committed
feat: Add locale validation and automatic locale setting for ActiveStorage attachments
1 parent b6f9fdd commit 96a32cc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

config/initializers/active_storage_locales.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ def self.included(base)
1515
validates :locale, presence: true
1616

1717
scope :for_locale, ->(locale) { where(locale: locale.to_s) }
18+
19+
before_validation :set_locale, on: :create
20+
21+
def set_locale
22+
return if locale.present?
23+
24+
self.locale = I18n.locale
25+
end
1826
end
1927
end
2028
end

0 commit comments

Comments
 (0)