[英]Devise Sendgrid & Cancancan : NameError in UserRegistrations#create
I receive always the same error whenever I try to signup a new user in my Rails app - I use Devise for registrations, CanCanCan and Sendgrid for sending the notification mail at the new user's email. 每当我尝试在Rails应用程序中注册新用户时,我总是收到相同的错误-我使用Devise进行注册,使用CanCanCan和Sendgrid通过新用户的电子邮件发送通知邮件。
The new user can signup, but then the error appears: 新用户可以注册,但是会出现错误:
NameError in UserRegistrations#create
Showing C:/Users/Adsidera/FreshObst/app/views/user_mailer/welcome.html.erb where line #4 raised:
undefined local variable or method `user' for #<#<Class:0x5777fb8>:0x5bdac78>
Rails.root: C:/Users/Adsidera/FreshObst
Application Trace | Framework Trace | Full Trace
app/views/user_mailer/welcome.html.erb:4:in `_app_views_user_mailer_welcome_html_erb__1004447735_47859732'
app/mailers/user_mailer.rb:14:in `welcome'
app/controllers/user_registrations_controller.rb:7:in `create'
This is the user_registrations_controller.rb 这是user_registrations_controller.rb
class UserRegistrationsController < Devise::RegistrationsController
before_filter :configure_permitted_parameters
def create
super
if @user.persisted?
UserMailer.welcome(@user).deliver_now
end
end
protected
# my custom fields are :name, :heard_how
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(:first_name, :last_name,
:email, :password, :password_confirmation)
end
devise_parameter_sanitizer.for(:account_update) do |u|
u.permit(:first_name,
:email, :password, :password_confirmation, :current_password)
end
end
end
And this is the user_mailer.rb 这是user_mailer.rb
class UserMailer < ApplicationMailer
default from: "freshobstuser@yahoo.com"
def contact_form(email, name, message)
@message = message
mail(:from => email,
:to => 'freshobstuser@yahoo.com',
:subject => 'A new contact form message from #{name}'
)
end
def welcome(user)
@appname = "FreshObst"
mail(:to => user.email,
:subject => "Welcome to #{@appname}!")
end
end
This is the link to my github as well https://github.com/Adsidera/FreshObst 这也是我的github的链接https://github.com/Adsidera/FreshObst
Thank you! 谢谢! I am getting nuts over it... Anna
我对此感到发疯...安娜
UPDATE! UPDATE!
After the advise by Illusionist, the issue seems half-solved, now I have this log: 在Illusionist的建议之后,这个问题似乎已经解决了一半,现在我有了以下日志:
UserMailer#welcome: processed outbound mail in 83.0ms
Sent mail to dummy@email.com (638.0ms)
Date: Fri, 04 Mar 2016 13:38:21 +0100
From: freshobstuser@yahoo.com
To: dummy@email.com
Message-ID: <56d981bd691e4_a241d243945917a@Adsidera-PC.mail>
Subject: Welcome to FreshObst!
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SMTPAPI: {"to":[ "mikecontin67@gmail.com" ]}
<html>
<body>
<table>
<tbody>
<tr>
<td><h2>Welcome Mike!</h2></td>
</tr><br>
<tr><td><p>Thank you for signing up with FreshObst</p></td>
</tr>
<tr><td><p>We wish you a fruity and healthy shopping by us ;) </p></td>
</tr>
<tr> <td><p><strong>Your FreshObst Team!</strong></p></td>
</tr><br><br>
<tr><td><p><small>This is an automated message. Please do not reply to this mail</small></p></td>
</tr>
</tbody>
</table>
</body>
</html>
Completed 500 Internal Server Error in 1048ms (ActiveRecord: 86.0ms)
Net::SMTPFatalError (550 Unauthenticated senders not allowed
):
app/controllers/user_registrations_controller.rb:7:in `create'
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (2.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (5.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (75.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (1.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (1.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (1.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (2.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (133.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (1.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.0ms)
Rendered C:/row/Ruby200/lib/ruby/gems/2.0.0/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (224.0ms)
SOLUTION of LAST ERROR : This last error though seemed to be caused by the yahoo.com mail address I chose per default, as from my SendGrid logs: "550 5.7.1 Unauthenticated email from yahoo.com is not accepted due to domain's DMARC policy. Please contact administrator of yahoo.com domain if this was a legitimate mail. Please visit https://support.google.com/mail/answer/2451690 to learn about DMARC initiative." 上一个错误的解决方案 :上一个错误似乎是由我默认选择的yahoo.com邮件地址引起的,从我的SendGrid日志中得出:“ 550 5.7.1由于域的DMARC策略,不接受来自yahoo.com的未经身份验证的电子邮件。如果这是一封合法邮件,请与yahoo.com域的管理员联系。请访问https://support.google.com/mail/answer/2451690以了解有关DMARC计划的信息。”
Changing then the default mailaddress to a non-yahoo mail address solved the issue. 然后将默认邮件地址更改为非Yahoo邮件地址即可解决此问题。 Thank you all a lot!
非常感谢大家!
try this 尝试这个
# in app/views/user_mailer/welcome.html.erb
<td><h2>Welcome <%= @user.first_name %>!</h2></td>
and 和
# in app/mailers/user_mailer.rb
def welcome(user)
@user = user
@appname = "FreshObst"
mail(:to => @user.email,
:subject => "Welcome to #{@appname}!")
end
SOLUTION TO LAST ERROR : This last error though seemed to be caused by the yahoo.com mail address I chose per default, as from my SendGrid logs: "550 5.7.1 Unauthenticated email from yahoo.com is not accepted due to domain's DMARC policy. Please contact administrator of yahoo.com domain if this was a legitimate mail. Please visit https://support.google.com/mail/answer/2451690 to learn about DMARC initiative." 解决最后一个错误的方法 :虽然这最后一个错误似乎是由我默认选择的yahoo.com邮件地址引起的,如我的SendGrid日志中所述:“ 550 5.7.1由于域的DMARC策略,不接受来自yahoo.com的未经身份验证的电子邮件。如果这是一封合法邮件,请与yahoo.com域的管理员联系。请访问https://support.google.com/mail/answer/2451690以了解有关DMARC计划的信息。”
Changing then the default mailaddress to a non-yahoo mail address solved the issue. 然后将默认邮件地址更改为非Yahoo邮件地址即可解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.