提问人:Chrismisballs 提问时间:10/21/2023 最后编辑:Chrismisballs 更新时间:10/22/2023 访问量:24
Rails 电子邮件操作文本附件link_to未显示
Rails email action text attachment link_to not showing
问:
实现模型后,一切正常,但是当我尝试将这些文章作为电子邮件发送时,提及无法正确呈现。我通过检查器看到了 和 ,但 html 只是为 . ☒@mentions
Article
has_rich_text
sgid
content
@mentions
rails mailer 预览显示一切正常,即提及正确呈现。但是,在生产中,它无法正确呈现。
编辑:
睡了一觉并重新访问了文档后,我意识到这不符合文档:link_to
由于 :host 通常在整个应用程序中是一致的,因此您可以 在 config/application.rb 中全局配置它:
config.action_mailer.default_url_options = { host: 'example.com' }
由于此行为,您不能使用任何 *_path 帮助程序 在电子邮件中。相反,您需要使用关联的 *_url 助手。例如,而不是使用
<%= link_to 'welcome', welcome_path %>
您将需要使用:
<%= link_to 'welcome', welcome_url %>
通过使用完整的 URL,您的链接现在可以在您的电子邮件中使用。
需要实施并找出来,将更新。阅读文档似乎传入不起作用:Active Record model
更简洁的是,当 name 是一个 Active Record 模型,它定义了 to_s返回默认值或模型实例属性的方法
link_to @profile
# => <a href="http://www.example.com/profiles/1">Eileen</a>
因此需要提供 also。url
任何想法为什么会/如何解决?
生产:
<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>
正如你所看到的,这只是创建一个“☒”。
开发:
<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>
这为拇外展者创造了一个。link_to
为了让网站在 / 中呈现内容,我有以下几点:ActionText
Trix
_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
答: 暂无答案
评论