Skip to content

Commit f1b8bb4

Browse files
authored
Merge pull request rails#35485 from excid3/default-attachable-trix-partial
Adds default trix content attachmment partial path
2 parents 4304373 + 764803e commit f1b8bb4

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

actiontext/lib/action_text/attachable.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def as_json(*)
6767
super.merge(attachable_sgid: attachable_sgid)
6868
end
6969

70+
def to_trix_content_attachment_partial_path
71+
to_partial_path
72+
end
73+
7074
def to_rich_text_attributes(attributes = {})
7175
attributes.dup.tap do |attrs|
7276
attrs[:sgid] = attachable_sgid
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Page < ApplicationRecord
2+
include ActionText::Attachable
3+
end
4+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class CreatePages < ActiveRecord::Migration[6.0]
2+
def change
3+
create_table :pages do |t|
4+
t.string :title
5+
6+
t.timestamps
7+
end
8+
end
9+
end

actiontext/test/dummy/db/schema.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2018_10_03_185713) do
13+
ActiveRecord::Schema.define(version: 2019_03_05_172303) do
1414

1515
create_table "action_text_rich_texts", force: :cascade do |t|
1616
t.string "name", null: false
@@ -49,6 +49,12 @@
4949
t.datetime "updated_at", precision: 6, null: false
5050
end
5151

52+
create_table "pages", force: :cascade do |t|
53+
t.string "title"
54+
t.datetime "created_at", precision: 6, null: false
55+
t.datetime "updated_at", precision: 6, null: false
56+
end
57+
5258
create_table "people", force: :cascade do |t|
5359
t.string "name"
5460
t.datetime "created_at", precision: 6, null: false

actiontext/test/unit/attachment_test.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
3232
assert_equal attachable.byte_size, trix_attachment.attributes["filesize"]
3333
assert_equal "Captioned", trix_attachment.attributes["caption"]
3434

35-
assert_nil trix_attachment.attributes["content"]
35+
assert_not_nil attachable.to_trix_content_attachment_partial_path
36+
assert_not_nil trix_attachment.attributes["content"]
3637
end
3738

3839
test "converts to TrixAttachment with content" do
@@ -49,6 +50,11 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
4950
assert_not_nil trix_attachment.attributes["content"]
5051
end
5152

53+
test "defaults trix partial to model partial" do
54+
attachable = Page.create! title: "Homepage"
55+
assert_equal "pages/page", attachable.to_trix_content_attachment_partial_path
56+
end
57+
5258
private
5359
def attachment_from_html(html)
5460
ActionText::Content.new(html).attachments.first

0 commit comments

Comments
 (0)