我强烈地感受到它的一个愚蠢的错误,我不知何故无法通过它看到的。我试图使用这段代码在我的邮包的看法。

<p><%= link_to 'here', unsubscribe_path(:email => "a@b.com") %></p>

和我在我的路线文件中定义了一个名为路线:

map.unsubscribe '/unsubscribe', :controller => :users, :action => :unsubscribe

所以,当我把我的电子邮件,这是我得到的链接:

http://b.comonly_pathtruecontrollerusersactionunsubscribe/

任何想法?谢谢 !

修改

这里的视图:

<html>
<body>
<p>
Hi, <br />

You have an alert for : <%= @alert.name %>. <br />

Here is some brief information about it: <br />

<%= @alert.details %><br /><br />
<br />Thank You,<br />
</p>
<p>
Click <p><%= link_to 'here', unsubscribe_path(:email => "a@b.com") %></p> to unsubscribe</p>
</body>
</html>

和这里的邮件:

class Alert < ActionMailer::Base

def send(alert, email)
  @subject = "hi"
  @recipients = "xyz@mail.com"
  @from = "xyz@mail.com"
  @sent_on = Time.now
  @content_type = "text/html"

  @alert = alert
  @email = email
end

有帮助吗?

解决方案

下面是一个工作模板的一个例子,我不能肯定地说,为什么你不工作,但尝试在通知生成的URL。

# notifier
def new_message_email(response)
    I18n.locale = response.recipient.language
    subject      I18n.t(:you_have_received_new_message_from_sender, :sender => response.sender.login)
    from         "info@domain.com"
    recipients   response.recipient.email
    content_type "text/html"
    sent_on      Time.now
    body         :sender_login => response.sender.login, :recipient_login => response.recipient.login
  end

#template
= word_wrap "Hi #{@recipient_login}."
= word_wrap ""
%p
= word_wrap "You have received a new personal message from #{@sender_login}.", :line_width => 60
= word_wrap "Click #{link_to 'here', account_inbox_url} to view your domain.com message inbox.", :line_width => 60
= word_wrap "If the above URL does not work try copying and pasting it into your browser. If you continue to have problems, please feel free to contact us at support@domain.com.", :line_width => 60

您将需要生成一个URL,而不是一个路径。

eg:
account_path => /account
account_url => http://domain.com/account

编辑: 这应该工作:

#notifier
body         :unsubscribe_url => unsubscribe_url(:email => "a@b.com")

#template
= word_wrap "Click #{@unsubscribe_url} to unsubscribe.", :line_width => 60

(见上面的例子为这一切如何结合在一起的)

其他提示

是否在任何其他视图此UNSUBSCRIBE_URL(或_path)工作?

返回的值看起来像什么从哈希制成转换成字符串。尝试致电.inspect返回的对象上“的link_to()?” - 也许会有一些线索

也许重新定义的东西在你的代码中的link_to方法的地方?使用“grep的高清*的link_to。” - 或许有些线索将在那里

一个测试可以是在此和以后的情况下是有用的。下面是一个例子(然而,这是我在轨道1使用,但我希望这不会在你的Rails版本相差太多)。

def test_routing
  assert_routing '/unsubscribe', {:controller => 'user', :action => 'unsubscribe'}
  assert_recognizes Hash[:controller => 'user', :action => 'unsubscribe'],
      {:path=>'/unsubscribe', :method => :get},
      {"email"=>"a@example.com"}
  # ..and so on
end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top