I am a Ruby on Rails developer with over two years of experience, most of which is working remotely. I am a typical Punekar and in my free time I play badminton, workout, go trekking and I like to interact with people. Feel free to slide into my DMs and say Hi! 😄
Until Rails 6,
by default,
actiontext’s default attachment HTML tag name was set to action-text-attachment.
An action text’s rich text field when rendered with an attachment would generate the following HTML:
We could change this tag name by parsing the rich_text output
and
then change the tag name using nokogiri.
After
Rails 7 added a cleaner and simpler way to do this with the option to set the default attachment HTML tag name using the following configuration option:
Note:
If we change the attachment HTML tag name in an existing Rails project,
all the previous attachment tag names will not be updated
and
hence not being rendered until we update the records with the new configuration in place.
If we try to render such a rich text record,
it will skip rendering the attachment HTML entirely as the tag will be
sanitized.
Restoring the tag name to the previous configuration will render the attachments as before.