我正在为我的学校设计一个项目,当学生注册时,他们必须查看其电子邮件中的链接以激活其帐户。在近300名学生中,大约有10名学生没有发送电子邮件。
日志显示:
ActionView::Template::Error: No route matches {:action=>"edit", :controller=>"account_activation", :email=>"example@gmail.com", :id=>nil}, possible unmatched constraints: [:id]
from app/views/user_mailer/account_activation.html.erb:9:in _app_views_user_mailer_account_activation_html_erb___3703118489382282531_47409448002620' from app/mailers/user_mailer.rb:6:inaccount_activation'
from app/models/user.rb:58:in `send_activation_email'
from (irb):3
无论我尝试什么,我都无法重现错误(出于隐私目的更改了电子邮件)
users_controller.rb
def create
@user = User.new(user_params)
if @user.save
@user.send_activation_email
flash[:info] = "Please check your email to activate your account"
redirect_to root_url
else
render 'new'
end
end
User.rb
def send_activation_email
UserMailer.account_activation(self).deliver
end
user_mailer.rb
def account_activation(user)
@user = user
mail( :to => @user.email, :subject => 'Account Activation | Student', :id => @user.activation_token)
end
我的account_activation_controller.rb
def edit
user = User.find_by(email: params[:email])
if user && !user.activated? && user.authenticated?(:activation, params[:id])
user.activate
log_in user
flash[:success] = "Account activated!"
redirect_to user
else
flash[:danger] = "Invalid activation link"
redirect_to root_url
end
end
我的github是https://github.com/Conbonbot/Community_Service_Logger
任何帮助将不胜感激