Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails友好的ID-ID作为slug-on-destroy方法处理_Ruby On Rails_Devise_Destroy_Friendly Id - Fatal编程技术网

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