Rails 3.2 haml电子邮件模板link_to错误 [英] rails 3.2 haml email template link_to error

查看:72
本文介绍了Rails 3.2 haml电子邮件模板link_to错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含haml(3.1.4)电子邮件的应用程序(rails 3.2).在电子邮件模板中,我想使用link_to,但是显然这4个都没有在生产环境中工作:

I have an application (rails 3.2) with haml (3.1.4) emails. In the email template I wanted to use link_to, but apparently none of those 4 is working in production:

#{link_to(my_models_url)}
= link_to(my_models_url)

/ @url set to my_models_url
#{link_to(@url)}
= link_to(@url)

在开发模式下,一切正常,但是在生产中,我不断遇到以下错误:

On development mode everything works fine, but in production, I keep getting the following error:

No route matches {}
 actionpack (3.2.0) lib/action_dispatch/routing/route_set.rb:503:in `raise_routing_error'

当我以前使用辅助方法时,它会起作用:

It works when I use helper methods before:

/ @my_link set to link_to(my_models_url)
#{@my_link}
= @my_link

但是这不方便,如果电子邮件中有更多链接,并且一般来说我不明白为什么前四个选项中的任何一个都不可行.我不知道这个问题是从哪里来的.在此方面的任何帮助,我将不胜感激.

But this is not convenient, if there are more links in the email and in general I don't see why any of the first 4 options should not be ok. I have no idea where is this problem comming from. I would appreciate any help on this...

解决方案:

由于有了iWasRobbed,我发现了问题所在:

Thanks to iWasRobbed I found where my problems were:

  1. 所有{resource} _path和{resource} _url必须在邮件程序中设置为@variables,它们在邮件程序视图中不可用
  2. 显然,mailer中的link_to()方法与rails视图中的方法不同...它始终需要2个参数,因此,除了在视图中可用的link_to(@link)之外,还需要做一个link_to(@ link,@ link) ). Pffff ...

推荐答案

您需要在mailer.rb文件中声明URL.这不是HAML问题,而是ActionMailer的设计方式.

You need to declare the URL within the mailer.rb file. This isn't a HAML issue so much as it's just the way ActionMailer was designed.

def some_mailer_here
  @url = my_models_url
end

然后在邮件视图中,您可以执行以下操作:

Then in your mailer view you can do:

= link_to("My models URL", @url)

http://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-in-action-mailer-views

这篇关于Rails 3.2 haml电子邮件模板link_to错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆