オーマイガー。どうやらできるようです!!!そこにそれを置けるなんて思いもよりませんでした。テンプレートの一番上(少なくとも私の頭の中では)でレンダリングされるのではなく。
digest_customが、私が確認して理解しようとしたコードの中で、.html_safeを呼び出していることがわかりました。しかし、括弧のない奇妙な構文を使用しているのが(私には)混乱を招きます。(あるいは、それを見つけられなかったかもしれません。)
ロケールで値を確認できますが、以前行っていたテンプレートの上書きと比較すると、これははるかにリスクの低い解決策です。
正しい道を示していただき、本当にありがとうございます!
もう一つ、ばかげていると感じていることがあります。私のdigest_custom_htmlは、それがレンダリングされるユーザーを必要とするため、ダイジェストが対象とするユーザーにアクセスできるように、@userを設定するためにdigestをオーバーライドしています。それを避けるために、何か非常に簡単な方法がありますか?
after_initialize do
# Code which should run after Rails has finished booting
# Railsの起動完了後に実行されるコード
# require_relative \"lib/discourse_add_jobs_to_digest/user_notifications_helper_override\"
require_relative \"lib/discourse_add_jobs_to_digest/engine\"
require_relative \"lib/discourse_add_jobs_to_digest/job_api\"
require_dependency \"user_notifications\"
module ::UserNotificationsHelperOverride
def digest_custom_html(position_key)
if position_key == "above_footer"
DiscourseAddJobsToDigest::JobApi.get_jobs_html(@user).html_safe
else
super
end
end
end
UserNotificationsHelper.prepend(::UserNotificationsHelperOverride)
module ::UserNotificationsOverride
def digest(user, opts = {})
@user = user
super
end
end
UserNotifications.prepend(::UserNotificationsOverride)
end