在此处输入图像描述 我遇到了一个问题,我无法解决。我创建了一个登录表单,我希望当它发送它时,用户会收到一封带有验证标志的电子邮件。但是当我发送表单时,我收到了这个错误:
用户#create 中的 ActionController::UrlGenerationError
没有路由匹配 {:action=>"confirm", :controller=>"users", :id=>26, :token=>"8ftJFxWKJqiMDDhtrqf1rVCq"},缺少必需的键:[:locale ]
谢谢你的帮助!
users_controller.rb
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.valid?
@user.save
UserMailer.confirm_email(@user).deliver_now
redirect_to :new
else
render 'new'
end
end
private
def user_params
params.require(:user).permit(:username, :email, :password, :password_confirmation)
end
路线.rb
scope "/:locale", locale: /en|fr|nl/ do
resources :projects, only:[:index]
resources :technos, only:[:index]
resources :blogs
resources :users, only: [:new, :create] do
member do
get 'confirm'
end
end
end
在confirm_email.html.erb
<%= confirm_user_url( id: @user.id, token: @user.confirmation_token ) %>
并在 user.rb
def confirm_email(user)
@user = user
mail( to: user.email, subject: "Votre inscription")
end