I tried using ActionText, which became available from Rails6, but I stumbled when I put in the initial data, so I decided to write about that time.
Rails:220.127.116.11 Model name to use: Post Column: title Rich text field name: content
First, make some posts easily
15.times do Post.create!(title: Faker::Book.unique.title) end
After that, you can put the initial data of ActionText by putting the data associated with Post into the ʻaction_text_rich_texts` table.
I think it will actually look like this.
Post.all.each do |post| ActionText::RichText.create!(record_type: 'Post', record_id: post.id, name: 'content', body: Faker::Lorem.sentence) end
Set record_type to the model name that uses ActionText, recor_id to the id of post, name to the rich text field name, and body to the text you actually want to put.
Finally, put it in and it's done.
If you can display it on the view side with this, I think that the input data is displayed.
If you want to insert line breaks and bold characters in the initial data, set as follows.
content = '<div class="trix-content"> <div><strong>Here is bold</strong>is.<br><br>The text here is broken</div> </div>' rich = ActionText::RichText.last rich.update(body: content)
If you check the view side with this, you should be able to prepare the initial data with line breaks and bold characters.
I wonder if articles with images can be prepared from the initial data. ..