Use rich_text instead of active_text

Just like we use has_many_attachments instead of active_storage_attachements.
This commit is contained in:
David Heinemeier Hansson 2018-04-13 14:10:18 -07:00
parent 7c4e70ea0b
commit 491bee6e64
7 changed files with 14 additions and 14 deletions

View File

@ -37,11 +37,11 @@ Assumes a Rails 5.2+ application with Active Storage and Webpacker installed.
```ruby
# app/models/message.rb
class Message < ActiveRecord::Base
active_text_attribute :content
has_rich_text :content
end
```
1. Replace form `text_area`s with `active_text_field`s:
1. Replace form `text_area`s with `rich_text_field`s:
```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">
<%= form.label :content %>
<%= form.active_text_field :content %>
<%= form.rich_text_field :content %>
</div>
<% end %>

View File

@ -2,7 +2,7 @@ module ActiveText
module TagHelper
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[:input] ||= "trix_input_#{ActiveText::TagHelper.id += 1}"
@ -26,7 +26,7 @@ module ActionView::Helpers
options = @options.stringify_keys
add_default_name_and_id(options)
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
def editable_value
@ -35,14 +35,14 @@ module ActionView::Helpers
end
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
end
end
class FormBuilder
def active_text_field(method, options = {})
@template.active_text_field(@object_name, method, objectify_options(options))
def rich_text_field(method, options = {})
@template.rich_text_field(@object_name, method, objectify_options(options))
end
end
end

View File

@ -53,7 +53,7 @@ module ActiveText
super.merge(attachable_sgid: attachable_sgid)
end
def to_active_text_attributes(attributes = {})
def to_rich_text_attributes(attributes = {})
attributes.dup.tap do |attributes|
attributes[:sgid] = attachable_sgid
attributes[:content_type] = attachable_content_type

View File

@ -20,7 +20,7 @@ module ActiveText
end
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)
end
end
@ -91,7 +91,7 @@ module ActiveText
end
def attachable_attributes
@attachable_attributes ||= (attachable.try(:to_active_text_attributes) || {}).stringify_keys
@attachable_attributes ||= (attachable.try(:to_rich_text_attributes) || {}).stringify_keys
end
def sgid_attributes

View File

@ -3,7 +3,7 @@ module ActiveText
extend ActiveSupport::Concern
class_methods do
def active_text_attribute(attribute_name)
def has_rich_text(attribute_name)
serialize(attribute_name, ActiveText::Content)
has_many_attached "#{attribute_name}_attachments"

View File

@ -1,3 +1,3 @@
class Message < ApplicationRecord
active_text_attribute :content
has_rich_text :content
end

View File

@ -18,7 +18,7 @@
<div class="field">
<%= form.label :content %>
<%= form.active_text_field :content, class: "trix-content" %>
<%= form.rich_text_field :content, class: "trix-content" %>
</div>
<div class="actions">