简体   繁体   English

在Maree应用程序中访问邮件程序类和视图中的URL帮助程序

[英]Accessing url helpers in mailer class and views in Spree application

I want to use one of the url helpers in a mailer class defined in my Spree application. 我想在我的Spree应用程序中定义的邮件程序类中使用其中一个url帮助程序。 So i did the following 所以我做了以下事情

Spree::CartonMailer.class_eval do
  include Rails.application.routes.url_helpers
end

This allows me to access the url helper in mailer class but then any url helper i call in the view or partials does not work. 这允许我访问邮件程序类中的url帮助程序,但是我在视图或部分中调用的任何url帮助程序都不起作用。 How can i make the url helpers work in both mailer class and the views/partials as well ? 如何使url助手在邮件程序类和视图/部分中都能正常工作?

Thank You 谢谢

Maybe you can use a variable with routes, like: 也许你可以使用带路线的变量,例如:

my_routes = Rails.application.routes.url_helpers

And use in ou code like: 并在ou代码中使用:

my_routes.root_path
my_routes.resource_path
...

No need to include Rails.application.routes.url_helpers 无需include Rails.application.routes.url_helpers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM