class Mobility::Backends::ActionText
Implements the {Mobility::Backends::KeyValue} backend for ActionText
.
@example
class Post < ApplicationRecord extend Mobility translates :content, backend: :action_text end post = Post.create(content: "<h1>My text is rich</h1>") post.rich_text_translations #=> #<ActionText::RichText::ActiveRecord_Associations_CollectionProxy ... > post.rich_text_translations.first.to_s #=> "<div class=\"trix-content\">\n <h1>My text is rich</h1>\n</div>\n" post.content #=> "<div class=\"trix-content\">\n <h1>My text is rich</h1>\n</div>\n" post.rich_text_translations.first.class #=> Mobility::Backends::ActionText::RichTextTranslation
Public Class Methods
configure(options)
click to toggle source
@!group Backend Configuration @option (see Mobility::Backends::KeyValue::ClassMethods#configure)
Calls superclass method
# File lib/mobility/backends/action_text.rb, line 41 def configure(options) options[:plain] = false unless options.has_key?(:plain) if options[:plain] options[:association_name] ||= 'plain_text_translations' options[:class_name] ||= PlainTextTranslation else options[:association_name] ||= 'rich_text_translations' options[:class_name] ||= RichTextTranslation end options[:key_column] ||= :name options[:value_column] ||= :body options[:belongs_to] ||= :record super end
valid_keys()
click to toggle source
Calls superclass method
# File lib/mobility/backends/action_text.rb, line 35 def valid_keys super.tap { |keys| keys.delete(:type) } << :plain end
Public Instance Methods
read(locale, **options)
click to toggle source
override to return record instead of value
Calls superclass method
# File lib/mobility/backends/action_text.rb, line 29 def read(locale, **options) return super if self.options[:plain] translation_for(locale, **options) end