2

When I save a model with action text, the content saves to the database, but it's not accessible through the console.

I have a Section model with has_rich_text :content

When I try to create a new record, it creates a rich text association, but the body is always blank.

section.content = '<p>Hello world</p>'
section.save
=> true
section.content
=> #<ActionText::RichText id: 6, name: "content", body: #<ActionText::Content " ">, record_type: "Section", record_id: 2, created_at: "2020-05-07 13:49:58", updated_at: "2020-05-07 14:00:36">
section.content.to_s
=> " "
section.content.body
=> #<ActionText::Content " ">

It properly sets in the database, and the value is being accessed by my code in a serializer and sending the proper content. However, I would like to gain access to this content through the console.

navi
  • 193
  • 2
  • 12

1 Answers1

1

It seems like there is a problem with ActionText when using API only setup.

See: https://github.com/rails/rails/issues/39266

The following code returns " " which should not be the case.

section.content.to_s
 => " "

section.content.body.to_s
 => " "

As an alternative, you can use the following:

section.content.body.to_html
 => "<p>Hello world</p>"

EDIT: I just noticed that the OP of this question and OP of the issue in Rails repository is the same. I will just put the answer to this for visibility as I encountered this problem myself and took me a while to found the issue in the Rails repository.

dcangulo
  • 1,888
  • 1
  • 16
  • 48