我正在使用许可并喜欢它,但我在重置密码方面遇到了麻烦。我输入我的电子邮件重置密码,这是有效的,但是当我尝试使用重置令牌导航到编辑密码页面时,我在禁用闪存错误时收到失败“请仔细检查URL或尝试再次提交表单“它把我重新引导回来。我在测试中得到了同样的错误。
我认为这与我的before_action语句有关,但我不知道如何修复它们。我研究过像this这样的问题无济于事。
我确定这是一个愚蠢的问题,但我是新人,所以我非常感谢任何帮助。如果这个代码不够,请告诉我。
class UsersController < Clearance::UsersController
before_action :require_login, only: [:create] # does this need to be in both user controllers?
...
def user_params
params.require(:user)
end
end
这是清关控制员。
class Clearance::UsersController < ApplicationController
before_action :require_login, only: [:create]
require 'will_paginate/array'
def new
@user = user_from_params
render template: 'users/new'
end
def create
@user = user_from_params
@user.regenerate_password
if @user.save
sign_in @user unless current_user
UserMailer.welcome_email(@user).deliver!
redirect_to users_path
else
render template: 'users/new'
end
end
def edit
@user = User.friendly.find(params[:id])
end
def update
@user = User.friendly.find(params[:id])
if @user.update(permit_params)
redirect_to @user
flash[:success] = "This profile has been updated."
else
render 'edit'
end
end
private
def avoid_sign_in
redirect_to Clearance.configuration.redirect_url
end
def url_after_create(user)
dashboards_path(user)
end
def user_from_params
user_params = params[:user] || Hash.new
is_public = check_public_params(user_params)
first_name = user_params.delete(:first_name)
last_name = user_params.delete(:last_name)
email = user_params.delete(:email)
password = user_params.delete(:password)
parish = user_params.delete(:parish)
division = user_params.delete(:division)
admin = user_params.delete(:admin)
Clearance.configuration.user_model.new(user_params).tap do |user|
user.first_name = first_name
user.last_name = last_name
user.password = password
user.email = email
user.is_public = is_public
user.parish_id = parish.to_i
user.division = division
user.admin = admin
end
end
def permit_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :is_public, :parish_id, :division, :admin)
end
end
编辑:routes.rb的相关部分
Rails.application.routes.draw do
resources :passwords, controller: "clearance/passwords", only: [:create, :new]
resource :session, controller: "clearance/sessions", only: [:create]
resources :users, controller: "clearance/users", only: [:create] do
resource :password,
controller: "clearance/passwords",
only: [:create, :edit, :update]
end
get "/sign_in" => "clearance/sessions#new", as: "sign_in"
delete "/sign_out" => "clearance/sessions#destroy", as: "sign_out"
get "/sign_up" => "clearance/users#new", as: "sign_up"
constraints Clearance::Constraints::SignedOut.new do
root to: 'high_voltage/pages#show', id: 'landing'
end
constraints Clearance::Constraints::SignedIn.new do
# root to: 'dashboards#index', as: :signed_in_root
root to: 'high_voltage/pages#show', id: 'parish_dashboard', as: :signed_in_root
end
# constraints Clearance::Constraints::SignedIn.new { |user| user.admin? } do
# root to: 'teams#index', as: :admin_root
# end
resources :users do
collection { post :import }
end
答案 0 :(得分:0)
事实证明,我在密码重置链接中找到用户实例的方式之间存在冲突。清除只需使用CreateProcessW(NULL, path.data(), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
即可找到用户,但由于我使用的是FriendlyId,因此需要将其更改为@user
。
所以不是......
@user.id
我做了
<%= link_to 'Change My Password', edit_user_password_url(@user, token: @user.confirmation_token.html_safe) %>
谢谢,尽管,这个伟大的宝石!