当用户创建密码update
时,操作被击中。设计sign_in(:user,@user)401错误
module Users
class PasswordController < ApplicationController
skip_before_action :authenticate_user!
before_action :set_user
def setup
render file: "#{Rails.root}/public/404" unless @user&.sign_in_count&.zero?
end
def update
if @user.update_attributes(password_params)
sign_in(:user, @user)
redirect_to root_path, notice: 'Setup complete'
else
flash[:alert] = errors(@user)
render :setup
end
end
private
def password_params
params.require(:user).permit(:password, :password_confirmation)
end
def set_user
@user = User.find_by(confirmation_token: params[:token])
end
end
end
当update
行动被击中。
这是控制台显示
Started PATCH "https://stackoverflow.com/users/password/wynEjv-E7uFp44EcwjbS" for ::1 at 2017-02-07 12:33:01 +1000
Processing by Users::PasswordController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"vIyPtidsM1GDNLh3n7gDDB2HzvR0QEEwAAvfMybNRn0/t4em4StiUVDyKwLC9i1OThoYguEae4T+xqLttjt1Pw==", "email"=>"[email protected]", "user"=>{"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Continue", "token"=>"wynEjv-E7uFp44EcwjbS"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = $1 LIMIT $2 [["confirmation_token", "wynEjv-E7uFp44EcwjbS"], ["LIMIT", 1]]
(0.1ms) BEGIN
SQL (0.5ms) UPDATE "users" SET "encrypted_password" = $1, "updated_at" = $2 WHERE "users"."id" = $3 [["encrypted_password", "$2a$11$o5wmmxnCv.rlPha52GR0IOG4tbhEJYNNF9tctcSLDMS/dvLAU0hXq"], ["updated_at", 2017-02-07 02:33:01 UTC], ["id", 9]]
(1.0ms) COMMIT
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 9], ["LIMIT", 1]]
(0.1ms) BEGIN
(0.2ms) COMMIT
Completed 401 Unauthorized in 129ms (ActiveRecord: 2.5ms)
有谁知道为什么sign_in
方法不在这里工作?
我用它在几个应用程序,然后它的工作。
感谢您提前给予任何帮助。
不要担心它的所有修复。用户需要首先使用设计进行确认。 – joeyk16