简体   繁体   English

发送电子邮件时URL格式错误。 Rails 3.2

[英]URLs wrongly formatted when sending emails. Rails 3.2

I have managed to send emails (gmail) from my Rails 3.2 application with no apparent problems. 我已经设法从Rails 3.2应用程序发送了电子邮件(gmail),没有明显的问题。 However, the urls genrated in email have the :id param wrongly positioned. 但是,电子邮件中生成的URL的:id参数位置错误。

NotificationMailer NotificationMailer

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

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

certainEmail.html.haml someEmail.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

The email at the inbox looks nice 收件箱中的电子邮件看起来不错

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

However, those both links urls are: 但是,这两个链接的网址都是:

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

And the SHOULD be: 并且应该是:

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

This happens with all/different mailers I got. 我收到的所有/不同邮件都会发生这种情况。 Is there anything obvious I am missing? 有什么明显的我想念的吗?

Thanks in advance! 提前致谢!

SOLUTION : 解决方案:

= 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)

这可能是一个路由问题,通常,如果您要链接到特定资源,则需要成员方法event_url(@comment.event)而不是作为收集方法的events_url

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

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