【问题标题】:URLs wrongly formatted when sending emails. Rails 3.2发送电子邮件时 URL 格式错误。导轨 3.2
【发布时间】:2013-04-09 18:59:24
【问题描述】:

我已经成功地从我的 Rails 3.2 应用程序发送电子邮件 (gmail),没有明显问题。但是,电子邮件中生成的 url 的 :id 参数位置错误。

通知邮件程序

default :from => 'no-reply@someDomaiin.com'
def report_spam(comment)
    @comment = comment

    mail(:to => "admin@someDomaiin.com", :subject => "Inappropriate content report")
  end

某些电子邮件.html.haml

Reported by:
"
= link_to @comment.reports.last.user.name, users_url(@comment.reports.last.user)
"
%p

Content of the accused comment:
%br
"
= link_to @comment.body, events_url(@comment.event.id)
"
%p

收件箱中的电子邮件看起来不错

Reported by: " saben "
Content of the accused comment: 
" I just created a superb event!! "

但是,这两个链接的网址是:

http://someDomaiin.heroku.com/saben/users
http://someDomaiin.heroku.com/2/events

应该是:

http://someDomaiin.heroku.com/users/saben
http://someDomaiin.heroku.com/events/2

这发生在我收到的所有/不同的邮件中。我有什么明显的遗漏吗?

提前致谢!

解决方案:

= link_to @comment.reports.last.user.name, user_url(:id => @comment.reports.last.user.id)
"
%p

Content of the accused comment:
%br
"
= link_to @comment.body, event_url(:id => @comment.event.id)

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 email actionmailer link-to


    【解决方案1】:

    这可能是路由问题,一般来说,如果您要链接到特定资源,则需要成员方法 event_url(@comment.event) 而不是 events_url ,这是一个集合方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 1970-01-01
      • 2019-11-22
      • 2015-03-17
      • 2016-05-06
      • 2016-04-09
      相关资源
      最近更新 更多