gpt4 book ai didi

ruby-on-rails - 如何在 Rails 3 link_to 语句中包含完整路径?

转载 作者:行者123 更新时间:2023-12-03 15:16:20 24 4
gpt4 key购买 nike

我正在尝试将 Rails link_to 语句放入包含完整路径的 Mailer 电子邮件中(即 - http://localhost/contacts/id/confirm)。我正在尝试的 link_to 语句适用于/pages/options 中的标准 View ,但不适用于 Mailer 电子邮件。

这是我的/pages/options Controller 代码:

class PagesController < ApplicationController
def options
end
end

这是页面/选项 View :
<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>

最佳答案

第一步:

#config/environments/production.rb
config.action_mailer.default_url_options = { :host => 'www.example.com' }

#config/environments/development.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }

第二步:
<%= link_to "here", confirm_contacts_url(17) %>

关于ruby-on-rails - 如何在 Rails 3 link_to 语句中包含完整路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9389874/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com