激活鏈接不工作 我嘗試刪除user.authenticated?(:activation, params[:id])
帳戶已激活 我不知道哪裏有問題。用戶帳戶總是彈出無效激活鏈接
user.rb
def authenticated?(attribute, token)
digest = send("#{attribute}_digest")
return false if digest.nil?
BCrypt::Password.new(digest).is_password?(token)
end
account_activations_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
user_controller.rb
def create
@user = User.new(user_params)
if @user.save
UserMailer.account_activation(@user).deliver_now
flash[:info] = "Please check your email to activate your account."
redirect_to root_url
else
render 'new'
end
end
account_activation.html.erb:
<h1>Sample_app</h1>
<p>
<%= @greeting %><%= @user.name %>
</p>
<p>
Welcome to the sample_app! Click on the link below to activate your account:
</p>
<%= link_to "Activate!", edit_account_activation_url(@user.activation_token, email: @user.email) %>
user_mailer.rb:
def account_activation(user)
@user = user
@greeting = "Hi"
mail to: @user.email, subject: "Account activation"
end
我的終端: enter image description here
我用params.insect
它顯示: { 「電子郵件」=> 「[email protected]」, 「控制器」= > 「account_activations」, 「動作」=> 「編輯」, 「ID」=> 「rPf9SJNob23cBpzomQ7O =例如」}
'' 3D '' 是添加在電子郵件的前面
[email protected] < --current
[email protected] < --error
嗨,歡迎來到Stack Overflow。您需要爲我們提供更多信息以幫助您。你所顯示的代碼似乎沒有任何錯誤。你可以請*編輯你的問題*並在那裏添加更多的代碼。請添加您使用的表單。請添加您收到的任何錯誤消息。你可以在'def edit'的第一行之前檢查'params'中的內容嗎?例如添加'puts params.inspect'作爲第一行。 –
如果我創建了一個新用戶,它會通過電子郵件發送這個「http:// localhost:3000/account_activations/7NG0m3JprYmaElG3Knsn = SA/edit?email = 3Dadmin%40example.com」 – maple