Ruby on rails 3 带设计的用户邮箱
我使用我的自定义邮件发送电子邮件。它在开发过程中工作得非常完美,但在生产过程中,我遇到了错误500,也就是当我试图在忘记时检索密码时 以下是生产模式下生产日志中的内容Ruby on rails 3 带设计的用户邮箱,ruby-on-rails-3,devise,ruby-on-rails-3.2,actionmailer,mailer,Ruby On Rails 3,Devise,Ruby On Rails 3.2,Actionmailer,Mailer,我使用我的自定义邮件发送电子邮件。它在开发过程中工作得非常完美,但在生产过程中,我遇到了错误500,也就是当我试图在忘记时检索密码时 以下是生产模式下生产日志中的内容 Processing by Devise::PasswordsController#create as HTML Parameters: {"utf8"=>"✓","authenticity_token"=>"xxxxxxxxxxxxxxx", "user"=>{"email"=>"sam@gmai
Processing by Devise::PasswordsController#create as HTML
Parameters: {"utf8"=>"✓","authenticity_token"=>"xxxxxxxxxxxxxxx", "user"=>{"email"=>"sam@gmail.com"}, "commit"=>"Send me r$
Completed 500 Internal Server Error in 2ms
NameError (uninitialized constant Devise::UserMailer):
activesupport (3.2.8) lib/active_support/inflector/methods.rb:230:in `block in constantize'
activesupport (3.2.8) lib/active_support/inflector/methods.rb:229:in `each'
activesupport (3.2.8) lib/active_support/inflector/methods.rb:229:in `constantize'
devise (2.1.2) lib/devise.rb:256:in `get'
devise (2.1.2) lib/devise.rb:279:in `mailer'
我的邮件程序配置。用户_mailer.rb
class UserMailer < Devise::Mailer
default :from => "info@xxxxxxxx.com"
def signup_confirmation(user)
@user = user
mail :to => user.email, :subject=> "Thank you for signing with us"
end
# send password reset instructions
def reset_password_instructions(user)
@resource = user
mail(:to => @resource.email, :subject => "Reset password instructions", :tag => 'password-reset', :content_type => "text/html") do |format|
format.html { render "devise/mailer/reset_password_instructions" }
end
end
end
非常感谢您的帮助好的,从表面上看,您的邮件似乎有误。特别是设置。默认情况下,您可以创建如下邮件程序:
class UserMailer < ActionMailer::Base
default :from => DEFAULT_FROM
def registration_confirmation(user)
@user = user
@url = "http://localhost:3000/login"
mail(:to => user.email, :subject => "Registered")
end
end
还有一件事。。。我注意到您的默认url是:config.action\u mailer.default\u url\u options={:host=>'https://xxxxxxxxxx.com“}
不需要https
,因此它应该看起来像config.action\u mailer.default\u url\u options={:host=>'xxxxxxxxx.com'}
。因为当你尝试发射任何东西时,会发生的是它正在做https://https://https://xxxxxxxxxx.com
。这是人们容易犯的错误
我还认为这可能是因为您没有设置负责发送电子邮件的类
其他可能解决您问题的解决方案
请注意,在config/initializers/designe.rb
中,注释掉了以下行:
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
取消对此的注释,并将其设置为您在示例中使用的类,以便
config.mailer = "UserMailer" # UserMailer is your mailer class
此外,在app/mailers/user_mailer.rb中,您应该具有:
class UserMailer < ActionMailer::Base
include Devise::Mailers::Helpers
default from: "default@mydomain.com"
def confirmation_instructions(record)
devise_mail(record, :confirmation_instructions)
end
def reset_password_instructions(record)
devise_mail(record, :reset_password_instructions)
end
def unlock_instructions(record)
devise_mail(record, :unlock_instructions)
end
# you can then put any of your own methods here
end
同时将电子邮件模板从app/views/designe/mailer/移动到app/views/user\mailer/
mv app/views/DEVICE/mailer/*app/views/user\U mailer/
好吧,从表面上看,你的邮递员好像错了。特别是设置。默认情况下,您可以创建如下邮件程序:
class UserMailer < ActionMailer::Base
default :from => DEFAULT_FROM
def registration_confirmation(user)
@user = user
@url = "http://localhost:3000/login"
mail(:to => user.email, :subject => "Registered")
end
end
还有一件事。。。我注意到您的默认url是:config.action\u mailer.default\u url\u options={:host=>'https://xxxxxxxxxx.com“}
不需要https
,因此它应该看起来像config.action\u mailer.default\u url\u options={:host=>'xxxxxxxxx.com'}
。因为当你尝试发射任何东西时,会发生的是它正在做https://https://https://xxxxxxxxxx.com
。这是人们容易犯的错误
我还认为这可能是因为您没有设置负责发送电子邮件的类
其他可能解决您问题的解决方案
请注意,在config/initializers/designe.rb
中,注释掉了以下行:
# Configure the class responsible to send e-mails.
# config.mailer = "Devise::Mailer"
取消对此的注释,并将其设置为您在示例中使用的类,以便
config.mailer = "UserMailer" # UserMailer is your mailer class
此外,在app/mailers/user_mailer.rb中,您应该具有:
class UserMailer < ActionMailer::Base
include Devise::Mailers::Helpers
default from: "default@mydomain.com"
def confirmation_instructions(record)
devise_mail(record, :confirmation_instructions)
end
def reset_password_instructions(record)
devise_mail(record, :reset_password_instructions)
end
def unlock_instructions(record)
devise_mail(record, :unlock_instructions)
end
# you can then put any of your own methods here
end
同时将电子邮件模板从app/views/designe/mailer/移动到app/views/user\mailer/
mv app/views/DEVICE/mailer/*app/views/user\U mailer/
照大卫说的去做。除了对大于3.2.4的装置进行更改之外
class UserMailer < ActionMailer::Base
include Devise::Mailers::Helpers
def confirmation_instructions(record, token, opts={})
@token = token
devise_mail(record, :confirmation_instructions, opts)
end
def reset_password_instructions(record, token, opts={})
@token = token
devise_mail(record, :reset_password_instructions, opts)
end
def unlock_instructions(record, token, opts={})
@token = token
devise_mail(record, :unlock_instructions, opts)
end
class UserMailer
照大卫说的做。除了对大于3.2.4的装置进行更改之外
class UserMailer < ActionMailer::Base
include Devise::Mailers::Helpers
def confirmation_instructions(record, token, opts={})
@token = token
devise_mail(record, :confirmation_instructions, opts)
end
def reset_password_instructions(record, token, opts={})
@token = token
devise_mail(record, :reset_password_instructions, opts)
end
def unlock_instructions(record, token, opts={})
@token = token
devise_mail(record, :unlock_instructions, opts)
end
class UserMailer
你能发布我发布的邮件配置吗。感谢您出于兴趣愿意帮助我。您是否在production.rb
中设置了smtp设置?如果是这样的话,发布这个!此外,为什么要在邮件中包含def reset\u password\u说明(用户)
。为您自动设计所有这一切/我的production.rb中有smtp设置。你可以发布你的邮件配置吗。感谢您出于兴趣愿意帮助我。您是否在production.rb
中设置了smtp设置?如果是这样的话,发布这个!此外,为什么要在邮件中包含def reset\u password\u说明(用户)
。为您自动设计所有这一切/我的production.rb中有smtp设置,似乎我搞错了。我应用了你的建议,现在一切都正常了fine@PetersonSamsam-如果这解决了您的问题,请接受Deave说明中的答案“谢谢”,上面写着从Deave继承您的邮件?谢谢,我好像被搞糊涂了。我应用了你的建议,现在一切都正常了fine@PetersonSamsam-如果这解决了您的问题,请接受Deave说明中的答案“谢谢”,上面写着从Deave继承您的邮件?你太棒了。非常感谢你!!你太棒了。非常感谢你!!