Module: LocalizedFrontend::ActiveRecordExtension::TranslatableColumnNames::ClassMethods

Defined in:
lib/localized_frontend/active_record_extension/translatable_column_names.rb

Instance Method Summary collapse

Instance Method Details

#localized_fields(options = {}) ⇒ Object

Stores a set of localized attributes in a hash, so that these localized variants can be used to localize validation error messages.

class Post < ActiveRecord::Base
  localized_fields :title => 'Smuuk smiik smakeke'
  validates_presence_of :title
end

p = Post.new
p.valid?
p.errors.full_messages # => ['Smuuk smiik smakeke is required']
# (fyi, the 'is required' part can also be localized)


27
28
29
30
# File 'lib/localized_frontend/active_record_extension/translatable_column_names.rb', line 27

def localized_fields(options = {})
  self.localized_attributes ||= HashWithIndifferentAccess.new
  self.localized_attributes.merge!(options)
end