1

I'm using Stimulus and ActionText to handle 'mentions', following the tutorial below;

User @mentions with ActionText

When displaying the actiontext content, the partial for each 'mention' is rendered from a json.builder file.

The issue that I'm having is that the actiontext content is within a turbo frame, and the mention partial contains a link. Therefore I need to add the following attribute to escape the turbo frame:

"data-turbo-frame": "_top"

For some reason, this attribute is being stripped from the page when rendering. (Using html.slim).

= link_to character.name, character_path(character), "data-turbo-frame": "_top", class: "font-semibold #{character.color} mention hover-trigger"

Resultant HTML:

<a class="font-semibold text-pink-700 mention hover-trigger" href="/characters/1">Example Character Name</a>
JesseWelch92
  • 109
  • 10
  • 1
    not familiar with `slim` but have you tried `data: {"turbo-frame" => "_top"}` instead? – engineersmnky Jan 05 '22 at 21:21
  • @engineersmnky, that is valid slim syntax but unfortunately still doesn't add the attribute to the link element. I'm beginning to think it could be something to do with stimulus, since that seems to make heavy use of 'data' attributes. – JesseWelch92 Jan 05 '22 at 22:03

1 Answers1

1

ActionText strips tags and html attributes that aren't whitelisted, including 'style' and the 'data-turbo-frame' attribute. To prevent this for a specific attribute, add the following to an initializer e.g. config/initializers/action_text.rb.

ActionText::Attachment::ATTRIBUTES << 'data-turbo-frame'

JesseWelch92
  • 109
  • 10