Use rich_text instead of active_text
Just like we use has_many_attachments instead of active_storage_attachements.
This commit is contained in:
parent
7c4e70ea0b
commit
491bee6e64
|
@ -37,11 +37,11 @@ Assumes a Rails 5.2+ application with Active Storage and Webpacker installed.
|
||||||
```ruby
|
```ruby
|
||||||
# app/models/message.rb
|
# app/models/message.rb
|
||||||
class Message < ActiveRecord::Base
|
class Message < ActiveRecord::Base
|
||||||
active_text_attribute :content
|
has_rich_text :content
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
1. Replace form `text_area`s with `active_text_field`s:
|
1. Replace form `text_area`s with `rich_text_field`s:
|
||||||
|
|
||||||
```erb
|
```erb
|
||||||
<%# app/views/messages/_form.html.erb %>
|
<%# app/views/messages/_form.html.erb %>
|
||||||
|
@ -49,7 +49,7 @@ Assumes a Rails 5.2+ application with Active Storage and Webpacker installed.
|
||||||
…
|
…
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= form.label :content %>
|
<%= form.label :content %>
|
||||||
<%= form.active_text_field :content %>
|
<%= form.rich_text_field :content %>
|
||||||
</div>
|
</div>
|
||||||
…
|
…
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -2,7 +2,7 @@ module ActiveText
|
||||||
module TagHelper
|
module TagHelper
|
||||||
cattr_accessor(:id, instance_accessor: false) { 0 }
|
cattr_accessor(:id, instance_accessor: false) { 0 }
|
||||||
|
|
||||||
def active_text_field_tag(name, value = nil, options = {})
|
def rich_text_field_tag(name, value = nil, options = {})
|
||||||
options = options.symbolize_keys
|
options = options.symbolize_keys
|
||||||
|
|
||||||
options[:input] ||= "trix_input_#{ActiveText::TagHelper.id += 1}"
|
options[:input] ||= "trix_input_#{ActiveText::TagHelper.id += 1}"
|
||||||
|
@ -26,7 +26,7 @@ module ActionView::Helpers
|
||||||
options = @options.stringify_keys
|
options = @options.stringify_keys
|
||||||
add_default_name_and_id(options)
|
add_default_name_and_id(options)
|
||||||
options["input"] ||= dom_id(object, [options["id"], :trix_input].compact.join("_"))
|
options["input"] ||= dom_id(object, [options["id"], :trix_input].compact.join("_"))
|
||||||
@template_object.active_text_field_tag(options.delete("name"), editable_value, options)
|
@template_object.rich_text_field_tag(options.delete("name"), editable_value, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def editable_value
|
def editable_value
|
||||||
|
@ -35,14 +35,14 @@ module ActionView::Helpers
|
||||||
end
|
end
|
||||||
|
|
||||||
module FormHelper
|
module FormHelper
|
||||||
def active_text_field(object_name, method, options = {})
|
def rich_text_field(object_name, method, options = {})
|
||||||
Tags::ActiveText.new(object_name, method, self, options).render
|
Tags::ActiveText.new(object_name, method, self, options).render
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class FormBuilder
|
class FormBuilder
|
||||||
def active_text_field(method, options = {})
|
def rich_text_field(method, options = {})
|
||||||
@template.active_text_field(@object_name, method, objectify_options(options))
|
@template.rich_text_field(@object_name, method, objectify_options(options))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,7 +53,7 @@ module ActiveText
|
||||||
super.merge(attachable_sgid: attachable_sgid)
|
super.merge(attachable_sgid: attachable_sgid)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_active_text_attributes(attributes = {})
|
def to_rich_text_attributes(attributes = {})
|
||||||
attributes.dup.tap do |attributes|
|
attributes.dup.tap do |attributes|
|
||||||
attributes[:sgid] = attachable_sgid
|
attributes[:sgid] = attachable_sgid
|
||||||
attributes[:content_type] = attachable_content_type
|
attributes[:content_type] = attachable_content_type
|
||||||
|
|
|
@ -20,7 +20,7 @@ module ActiveText
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_attachable(attachable, attributes = {})
|
def from_attachable(attachable, attributes = {})
|
||||||
if node = node_from_attributes(attachable.to_active_text_attributes(attributes))
|
if node = node_from_attributes(attachable.to_rich_text_attributes(attributes))
|
||||||
new(node, attachable)
|
new(node, attachable)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -91,7 +91,7 @@ module ActiveText
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachable_attributes
|
def attachable_attributes
|
||||||
@attachable_attributes ||= (attachable.try(:to_active_text_attributes) || {}).stringify_keys
|
@attachable_attributes ||= (attachable.try(:to_rich_text_attributes) || {}).stringify_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
def sgid_attributes
|
def sgid_attributes
|
||||||
|
|
|
@ -3,7 +3,7 @@ module ActiveText
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
class_methods do
|
class_methods do
|
||||||
def active_text_attribute(attribute_name)
|
def has_rich_text(attribute_name)
|
||||||
serialize(attribute_name, ActiveText::Content)
|
serialize(attribute_name, ActiveText::Content)
|
||||||
|
|
||||||
has_many_attached "#{attribute_name}_attachments"
|
has_many_attached "#{attribute_name}_attachments"
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
class Message < ApplicationRecord
|
class Message < ApplicationRecord
|
||||||
active_text_attribute :content
|
has_rich_text :content
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= form.label :content %>
|
<%= form.label :content %>
|
||||||
<%= form.active_text_field :content, class: "trix-content" %>
|
<%= form.rich_text_field :content, class: "trix-content" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
|
|
Loading…
Reference in New Issue