aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2018-10-02 17:30:22 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2018-10-02 17:30:22 -0700
commit1663bfad247732aa928e60489d4d394e338d1c49 (patch)
tree103f816fae59abf46f3a300ab34e3b1815ec97f3 /app
parent283023f826165153d23d2373e1e023f873a46b41 (diff)
downloadrails-1663bfad247732aa928e60489d4d394e338d1c49.tar.gz
rails-1663bfad247732aa928e60489d4d394e338d1c49.tar.bz2
rails-1663bfad247732aa928e60489d4d394e338d1c49.zip
Add a bit more documentation
Diffstat (limited to 'app')
-rw-r--r--app/helpers/action_text/tag_helper.rb23
-rw-r--r--app/models/action_text/rich_text.rb4
2 files changed, 27 insertions, 0 deletions
diff --git a/app/helpers/action_text/tag_helper.rb b/app/helpers/action_text/tag_helper.rb
index 28c62166dd..8d1ff0aaad 100644
--- a/app/helpers/action_text/tag_helper.rb
+++ b/app/helpers/action_text/tag_helper.rb
@@ -2,6 +2,17 @@ module ActionText
module TagHelper
cattr_accessor(:id, instance_accessor: false) { 0 }
+ # Returns a `trix-editor` tag that instantiates the Trix JavaScript editor as well as a hidden field
+ # that Trix will write to on changes, so the content will be sent on form submissions.
+ #
+ # ==== Options
+ # * <tt>:class</tt> - Defaults to "trix-content" which ensures default styling is applied.
+ #
+ # ==== Example
+ #
+ # rich_text_area_tag "content", message.content
+ # # <input type="hidden" name="content" id="trix_input_post_1">
+ # # <trix-editor id="content" input="trix_input_post_1" class="trix-content" ...></trix-editor>
def rich_text_area_tag(name, value = nil, options = {})
options = options.symbolize_keys
@@ -37,6 +48,18 @@ module ActionView::Helpers
end
module FormHelper
+ # Returns a `trix-editor` tag that instantiates the Trix JavaScript editor as well as a hidden field
+ # that Trix will write to on changes, so the content will be sent on form submissions.
+ #
+ # ==== Options
+ # * <tt>:class</tt> - Defaults to "trix-content" which ensures default styling is applied.
+ #
+ # ==== Example
+ # form_with(model: @message) do |form|
+ # form.rich_text_area :content
+ # end
+ # # <input type="hidden" name="message[content]" id="message_content_trix_input_message_1">
+ # # <trix-editor id="content" input="message_content_trix_input_message_1" class="trix-content" ...></trix-editor>
def rich_text_area(object_name, method, options = {})
Tags::ActionText.new(object_name, method, self, options).render
end
diff --git a/app/models/action_text/rich_text.rb b/app/models/action_text/rich_text.rb
index 0b6043bd74..94cf595fac 100644
--- a/app/models/action_text/rich_text.rb
+++ b/app/models/action_text/rich_text.rb
@@ -1,3 +1,7 @@
+# The RichText record holds the content produced by the Trix editor in a serialized `body` attribute.
+# It also holds all the references to the embedded files, which are stored using Active Storage.
+# This record is then associated with the Active Record model the application desires to have
+# rich text content using the `has_rich_text` class method.
class ActionText::RichText < ActiveRecord::Base
self.table_name = "action_text_rich_texts"