Ruby on rails RubyonRails友好的ID-ID作为slug-on-destroy方法处理
除了我的用户模型的销毁方法外,一切都很好。我现在相当肯定,这与友谊宝石有关 如果我需要密码,则会出现Ruby on rails RubyonRails友好的ID-ID作为slug-on-destroy方法处理,ruby-on-rails,devise,destroy,friendly-id,Ruby On Rails,Devise,Destroy,Friendly Id,除了我的用户模型的销毁方法外,一切都很好。我现在相当肯定,这与友谊宝石有关 如果我需要密码,则会出现无效密码错误。 如果我不需要密码,则用户“显然”会删除,但不会。(我的flash[:success]显示相应的重定向) 服务器日志: Processing by UsersController#destroy as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"SkfqooVdKgfsgoL78+yZDxSYoTJNqz
无效密码
错误。
如果我不需要密码,则用户
“显然”会删除,但不会。(我的flash[:success]
显示相应的重定向)
服务器日志:
Processing by UsersController#destroy as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"SkfqooVdKgfsgoL78+yZDxSYoTJNqzUfmyWfGTv8LOxSEObnaKEhip837yrEK5bHVO0HJ/6dmKHqUZmiiWoqDg==", "user"=>{"current_password"=>"[FILTERED]"}, "commit"=>"Delete", "locale"=>"en", "id"=>"e2dc"}
这里,ID显示为“e2dc”,而不是实际ID 20。(e2dc是当前用户的用户名和slug)
class用户
我尝试过使用
用户友好型。查找时没有任何运气。在我的项目中,其他一切都有效
感谢您的建议,请尝试以下方法:
def destroy
@user = User.find(params[:id])
if @user.destroy_with_password(params[:user][:current_password])
redirect_to feedbacks_url, notice: "User deleted."
else
flash.now[:notice] = @user.errors.full_messages
render "account"
end
end
虽然我不明白为什么,但这很有效。对于控制器中的其他方法,(我甚至在同一个控制器中有一个更新方法,用户使用密码(user\u params)更新\u
我可以使用user@user=current\u user
或查找(params[:id])
。谢谢!!
def destroy
@user = User.find(params[:id])
if @user.destroy_with_password(params[:user][:current_password])
redirect_to feedbacks_url, notice: "User deleted."
else
flash.now[:notice] = @user.errors.full_messages
render "account"
end
end