我正在尝试在包含完整路径的邮件程序电子邮件中放入Rails link_to语句(即 - http://localhost/contacts/id/confirm)。我尝试的link_to语句在我的标准View in/pages/options中工作,但不在Mailer email中。如何在Rails 3 link_to语句中包含完整路径?
这是我/页/选项控制器代码:
class PagesController < ApplicationController
def options
end
end
而这里的页/选项查看:
<div>
<%= link_to "here", :controller => "contacts", :action => "confirm",
:only_path => false, :id => 17 %>
</div>
当我把这个链接到以下邮件(welcome_email.html。 RB),我得到下面的错误。任何帮助,将不胜感激。
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<%= link_to "here", :controller => "contacts", :action => "confirm",
:only_path => false, :id => 17 %>
</body>
</html>
错误消息:
RuntimeError in Contacts#create
Showing C:/Documents and Settings/Corey Quillen/My Documents/Dev/Dev
Projects/my_project
Project/my_project/app/views/user_mailer/welcome_email.html.erb where line #7
raised:
Missing host to link to! Please provide :host parameter or set
default_url_options[:host]
Extracted source (around line #7):
4: <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
5: </head>
6: <body>
7: <%= link_to "here", :controller => "contacts", :action => "confirm", :only_path
=> false, :id => 17 %>
8: </body>
9: </html>
完美地工作!谢谢(和其他人)的帮助! – 2012-02-23 10:24:22