激活链接不起作用
我尝试删除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
它显示:
{&#34;电子邮件&#34; =&gt;&#34; 3Dadmin@example.com",&#34;控制器&#34; =&gt;&#34; account_activations&#34;,&#34;行动& #34; =&gt;&#34;编辑&#34;,&#34; id&#34; =&gt;&#34; rPf9SJNob23cBpzomQ7O =例如&#34;}
&#39;&#39; 3D&#39;&#39;添加在电子邮件前面
admin@example.com&lt; - 当前
3Dadmin@example.com&lt; - 错误
答案 0 :(得分:0)
您不应该为激活发送编辑链接。要激活用户......你想要别的东西。
我猜是这样的:
<%= link_to "Activate!", account_activation_url(@user.activation_token) %>
我可能在您需要的确切链接上出错,但我确定编辑链接有误...所以请阅读有关您应该做什么的文档。