【问题标题】:Full URL is not coming when using action mailer in Rail 3?在 Rail 3 中使用 action mailer 时没有完整的 URL?
【发布时间】:2015-03-30 10:37:18
【问题描述】:

我正在尝试使用 Ruby on Rails 在我的应用程序中实现重置密码功能。我正在使用操作邮件发送到用户电子邮件的链接。电子邮件正在通过链接发送给用户,但是当用户单击该链接时,完整的 URL没有来(即“localhost:3000/homes/resetpass”)。只有“/homes/resetpass”来了。请检查我的以下代码并帮助我解决这个问题。

views/user_mailer/registration_confirmation.html.erb

<p><%= @users.first_name %>,</p>

<p>Thank you for registering!</p>

<p>Edit Your Password <%= link_to "Click Here",homes_resetpass_path(:id => @users.id ),:host => "localhost:3000" %></p>

mailers/user_mailers.rb

class UserMailer < ActionMailer::Base
  default from: "rajatpradhan474@gmail.com"
  def registration_confirmation(user)  
  @users = user  
  mail(:to => user.email, :subject => "Registered")  
end  
end

config/initializers/setup_mail.rb

ActionMailer::Base.smtp_settings = {  
  :address              => "smtp.gmail.com",  
  :port                 => 587,  
  :domain               => "gmail.com",  
  :user_name            => "rajatpradhan474@gmail.com",  
  :password             => "**********",  
  :authentication       => "plain",  
  :enable_starttls_auto => true  
} 
ActionMailer::Base.default_url_options[:host] = "localhost:3000"  

【问题讨论】:

    标签: ruby ruby-on-rails-3 email


    【解决方案1】:

    您需要使用url_for 而不是link_to。链接页面描述了如何以及为什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-31
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      • 1970-01-01
      • 2018-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多