Add ability to filter followed accounts' posts by language (#19095)
This commit is contained in:
parent
882e54c786
commit
50948b46aa
30 changed files with 298 additions and 39 deletions
21
app/validators/language_validator.rb
Normal file
21
app/validators/language_validator.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class LanguageValidator < ActiveModel::EachValidator
|
||||
include LanguagesHelper
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
record.errors.add(attribute, :invalid) unless valid?(value)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def valid?(str)
|
||||
if str.nil?
|
||||
true
|
||||
elsif str.is_a?(Array)
|
||||
str.all? { |x| valid_locale?(x) }
|
||||
else
|
||||
valid_locale?(str)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue