Ruby on Rails - Friendly-ID - ID 在销毁方法中被处理为 slug

Ruby on Rails - Friendly-ID - Id is processed as slug on destroy method

除了我的用户模型的销毁方法外,一切正常。我现在非常确定它与 Friendly_ID gem 有关。

如果我需要密码,则会收到 invalid password 错误。 如果我不需要密码,那么 User 'apparently' 会删除,但它不会。 (我的 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 User < ActiveRecord::Base
  extend FriendlyId
  friendly_id :username, use: [:slugged, :finders]
end

class UsersController < ApplicationController

  def destroy
    @user = current_user
    @user.id = params[:user_id]
    if @user.destroy_with_password(user_params)
        redirect_to feedbacks_url, notice: "User deleted."
    else
      render "account"
      flash.now[:notice] = @user.errors.full_messages
    end
  end
end

<%= simple_form_for(@user, :method => :delete) do |f| %>
  <%= f.input :current_password, autocomplete: "off", required: true %>
  <%= f.button :submit, "Delete" %>
<% end %>

我曾尝试使用 User.friendly.find,但没有成功。我的项目中的其他一切都有效。

感谢任何建议

尝试以下操作:

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