File tree Expand file tree Collapse file tree 5 files changed +31
-2
lines changed Expand file tree Collapse file tree 5 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,10 @@ def as_json(*)
67
67
super . merge ( attachable_sgid : attachable_sgid )
68
68
end
69
69
70
+ def to_trix_content_attachment_partial_path
71
+ to_partial_path
72
+ end
73
+
70
74
def to_rich_text_attributes ( attributes = { } )
71
75
attributes . dup . tap do |attrs |
72
76
attrs [ :sgid ] = attachable_sgid
Original file line number Diff line number Diff line change
1
+ class Page < ApplicationRecord
2
+ include ActionText ::Attachable
3
+ end
4
+
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 10
10
#
11
11
# It's strongly recommended that you check this file into your version control system.
12
12
13
- ActiveRecord ::Schema . define ( version : 2018_10_03_185713 ) do
13
+ ActiveRecord ::Schema . define ( version : 2019_03_05_172303 ) do
14
14
15
15
create_table "action_text_rich_texts" , force : :cascade do |t |
16
16
t . string "name" , null : false
49
49
t . datetime "updated_at" , precision : 6 , null : false
50
50
end
51
51
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
+
52
58
create_table "people" , force : :cascade do |t |
53
59
t . string "name"
54
60
t . datetime "created_at" , precision : 6 , null : false
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
32
32
assert_equal attachable . byte_size , trix_attachment . attributes [ "filesize" ]
33
33
assert_equal "Captioned" , trix_attachment . attributes [ "caption" ]
34
34
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" ]
36
37
end
37
38
38
39
test "converts to TrixAttachment with content" do
@@ -49,6 +50,11 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
49
50
assert_not_nil trix_attachment . attributes [ "content" ]
50
51
end
51
52
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
+
52
58
private
53
59
def attachment_from_html ( html )
54
60
ActionText ::Content . new ( html ) . attachments . first
You can’t perform that action at this time.
0 commit comments