UPDATE: This seems to be happening on an --api
only build, which is what I use. It can be reproduced by creating a new rails project with the --api
flag.
@model.content.body.to_html
seems to return the proper content.
I am having a problem using ActionText. I've had this problem for a while, and I can't find any answers online, so I'm hoping someone can help me troubleshoot.
Sometimes, I can't get access to the ActionText values.
I included this in my Section
model:
has_rich_text :content
I can set the data by doing:
@section.content = "<p>Hello world</p>"
However, I cannot see the text in my console, nor erb templates. I see it just as an empty string, or in the mailer template, it doesn't show up at all.
section.content
=> #<ActionText::RichText id: 1, name: "content", body: #<ActionText::Content " ">, record_type: "Section", record_id: "f9c5743c-fb16-411e-82ad-325817849a40", created_at: "2020-05-09 14:54:48", updated_at: "2020-05-13 01:35:34">
section.content.body
=> #<ActionText::Content " ">
section.content.body.to_s
=> " "
section.content.to_json
=> "{\"id\":1,\"name\":\"content\",\"body\":\"\\u003cdiv\\u003e\\u003c!--block--\\u003eThis is an overview for Chapter 1.\\u003c/div\\u003e\",\"record_type\":\"Section\",\"record_id\":\"f9c5743c-fb16-411e-82ad-325817849a40\",\"created_at\":\"2020-05-09T10:54:48.633-04:00\",\"updated_at\":\"2020-05-12T21:35:34.546-04:00\"}"
section.content.body.to_json
=> "\"\\u003cdiv\\u003e\\u003c!--block--\\u003eThis is an overview for Chapter 1.\\u003c/div\\u003e\""
I can't seem to access the value, unless I convert it to JSON. The value gets pulled fine in my API Serializer as well, but that is also JSON. I can't access it from the rails console, nor in my mailer templates, and I'm currrently outputting it in my template like this:
<%= JSON.parse(@chapter.sections.first.content.body.to_json).html_safe %>
How do I get access to the value, or any thoughts on how to troubleshoot?
Thank you.
Rails 6.0.3
ruby 2.7.1p83