Module: LocalizableModel::ActiveRecordExtension
- Defined in:
- lib/localizable_model/active_record_extension.rb
Overview
LocalizableModel::ActiveRecordExtension
Extends ActiveRecord::Base with the localizable setup method.
Instance Method Summary collapse
-
#localizable(&block) ⇒ Object
Extends the model with Localizable features.
Instance Method Details
#localizable(&block) ⇒ Object
Extends the model with Localizable features. It takes an optional block as argument, which yields an instance of LocalizableModel::Configuration.
Example:
class Page < ActiveRecord::Base
localizable do
attribute :name
attribute :body
end
end
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/localizable_model/active_record_extension.rb', line 22 def localizable(&block) unless is_a?(LocalizableModel::ClassMethods) send :extend, LocalizableModel::ClassMethods send :include, LocalizableModel::InstanceMethods has_many(:localizations, as: :localizable, dependent: :destroy, autosave: true) before_save :cleanup_localizations! end localizable_configuration.instance_eval(&block) if block_given? define_localizable_methods! end |