JesseWelch92
JesseWelch92

Reputation: 109

How to render action text as plain text including attachment content

I have a simple 'Character' model with a rich text field, description. In this field you can 'tag' other characters by inserting an attachment relevant to them. (Followed this tutorial: https://gorails.com/episodes/at-mentions-with-actiontext).

When rendering this description field onto the page, you correctly see the contents of the '_character' partial where the attachment is referenced, however I'm unable to pass the contents of the description field to something like prawn. Predictably, it throws an 'undefined method `encode' for #ActionText::RichText:0x000056220d5e6930' error.

Using description.to_plain_text outputs the contents of the field without the attachments, which is accepted by prawn, however I need the output to include the Character name as plain text.

# _character.html.erb

<span class="font-semibold #{character.color} mention">
  <%= link_to character_path(character), "data-turbo-frame": "_top" do %>
    <%= character.name %>
  <% end %>
</span>

Is there a function or method I can use to output the description field as plain text inclusive of a different partial / just the character.name attribute where the action-text-attachments are? Obviously they'd need to check the sgid referenced in the attachment.

Upvotes: 1

Views: 772

Answers (0)

Related Questions