After implementing @mentions
to Article
models has_rich_text
, everything works fine but when I try to send these articles as an email, the mentions fail to render right. I see sgid
and content
, via the inspector but the html just renders a "☒" for the @mentions
.
The rails mailer preview shows everything fine, i.e. the mention renders correctly. However, in production it fails to render correctly.
EDIT:
After getting some sleep and revisitng the docs I realized that link_to
wont work per the docs:
As the :host usually is consistent across the application you can configure it globally in config/application.rb:
config.action_mailer.default_url_options = { host: 'example.com' }
Because of this behavior, you cannot use any of the *_path helpers inside of an email. Instead, you will need to use the associated *_url helper. For example instead of using
<%= link_to 'welcome', welcome_path %>
You will need to use:
<%= link_to 'welcome', welcome_url %>
By using the full URL, your links will now work in your emails.
Need to implement and find out, will update. Reading the docs it seems that Passing in the Active Record model
does not work:
More concise yet, when name is an Active Record model that defines a to_s method returning a default value or a model instance attribute
link_to @profile
# => <a href="http://www.example.com/profiles/1">Eileen</a>
therefore need to provide the url
also.
Any ideas why this would be/how to fix?
Production:
<action-text-attachment sgid="eyJfcmFpbHMiOnspJaXhuYVdRNkx5OWhjRE12VFhWelkyeGxMekUyUDJWNGNkZWQT09IiwiZXhwIjpudWxsLCJwdXIiOiJhdHRhY2hhYmxlIn19--31217260f33fc8fce3243" content-type="application/octet-stream" content="<a data-turbo-frame="_top" data-class="description" target="_blank" href="/gadgets/muscles/triceps-brachii">
Triceps Brachii
</a>">☒</action-text-attachment>
This just creates an "☒" as you can see.
Dev:
<action-text-attachment sgid="eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaTFuYVdRNkx5OWhjR1Y0TFcxdmNuUDJsdUJqb0dSVlE9IiwiZXhwIjhdHRhY2hhYmxlIn19--391d3670aff9" content-type="application/octet-stream" content=" <a data-turbo-frame="_top" data-class="description" target="_blank" href="/gadgets/muscles/abductor-hallucis">
Abductor Hallucis
</a>"> <a href="/gadgets/muscles/abductor-hallucis">
Abductor Hallucis
</a></action-text-attachment>
Which creates a link_to
for Abductor Hallucis.
For the site to render the content inside ActionText
/Trix
, I have the following:
_exercise_mention.html.erb:
<%= link_to exercise, data: { turbo_frame: "_top", class: "description" }, target: :_blank do %>
<%= exercise.name.humanize.titleize %>
<% end %>
_exercise_mention.jbuilder:
json.extract! exercise, :id, :name
json.sgid exercise.attachable_sgid
json.content render(partial: "exercises/exercise_mention", locals: { exercise: exercise }, formats: [:html])
Exercise model:
class Exercise < ApplicationRecord
include ActionText::Attachable
......
#show mentions Article
def to_trix_content_attachment_partial_path
"exercises/exercise_mention"
end
#edit mentions Article
def to_attachable_partial_path
"exercises/exercise_mention"
end
end