我需要在观察者中访问 url_helper 方法,我该怎么做?

发布于 2024-12-13 17:28:40 字数 195 浏览 5 评论 0原文

我有一个观察者,用于生成一些活动日志。

这些活动日志需要有指向实际站点活动的链接,以便在显示它们时可以轻松跳转到相应的页面。但是观察者无法访问 url_helpers (至少默认情况下)。

如果我不存储简单的链接,那么我将不得不存储该链接应该指向的页面的详细信息,然后稍后进行反序列化,这看起来很愚蠢。

如何在观察者内生成链接?

I've got an observer that is being used to generate some activity logs.

Those activity logs need to have links to the actual site activities so that when they're displayed it's easy to jump to the corresponding page. However observers can't access url_helpers (at least by default).

If I don't store the simple link then I'm going to have to store the details of the page that the link should be to and then deserialize later which seems pretty silly.

How can I generate a link within the observer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十年九夏 2024-12-20 17:28:40

只需使用 Rails.application.routes.url_helpers.yourhelper_path 尝试一下

Just try it with Rails.application.routes.url_helpers.yourhelper_path

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文