邮件程序视图中可用的帮助程序方法取决于环境? [英] Helper methods available in mailer views depend on environment?

查看:90
本文介绍了邮件程序视图中可用的帮助程序方法取决于环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与我的上一个问题有关我想了解一件事-为什么这样做:

Related to my previous question I still have one thing that I would like to understand - why this:

= link_to(root_path)
= link_to(@some_path_set_in_mailer)

在开发模式下工作(config.action_mailer.perform_deliveries设置为true,并且实际发送了电子邮件),并且在生产或分期中必须更改为:

works in development mode (config.action_mailer.perform_deliveries was set to true and emails were actually sent) and in production or staging has to be changed to:

= link_to(@some_path_set_in_mailer, @some_path_set_in_mailer)

以避免没有路线匹配{}错误?

to avoid "No route matches {}" error?

我在Rails 3.2中遇到了这个问题。

I had this problem in rails 3.2.

推荐答案

我不完全确定为什么会有区别,因为不应该这样。

I'm not entirely sure why there is a difference since there shouldn't be.

但是, link_to 通常具有以下格式:

However, link_to typically has this format:

= link_to("Some link description here", root_path)

通常,只有当您需要在 do 块中放置较长的描述时,才会通常省略链接描述文本:

The only time you typically leave off the link description text is if you have a longer description that you need to put within a do block like this:

= link_to(root_path) do
  %p Some link description here
  = image_tag("some_image.jpg")

所以我建议您坚持使用上述首选语法。

So I would recommend sticking to the preferred syntaxes above.

link_to 的文档并没有真正谈论您使用过多的速记方法。

The docs for link_to don't really talk about the short-hand method you're using too much.

以下是其来源:

# File actionpack/lib/action_view/helpers/url_helper.rb, line 231
def link_to(*args, &block)
  if block_given?
    options      = args.first || {}
    html_options = args.second
    link_to(capture(&block), options, html_options)
  else
    name         = args[0]
    # this is probably where your issue is coming from
    options      = args[1] || {}
    html_options = args[2]

    html_options = convert_options_to_data_attributes(options, html_options)
    url = url_for(options)

    href = html_options['href']
    tag_options = tag_options(html_options)

    href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
    "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
  end
end

这篇关于邮件程序视图中可用的帮助程序方法取决于环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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