我需要在观察者中访问 url_helper 方法,我该怎么做?
我有一个观察者,用于生成一些活动日志。
这些活动日志需要有指向实际站点活动的链接,以便在显示它们时可以轻松跳转到相应的页面。但是观察者无法访问 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用 Rails.application.routes.url_helpers.yourhelper_path 尝试一下
Just try it with Rails.application.routes.url_helpers.yourhelper_path