我正在嘗試在包含完整路徑的郵件程序電子郵件中放入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