Rails 5: FriendlyId TypeError (错误的参数类型符号(预期的模块:))

Rails 5: FriendlyId TypeError (wrong argument type Symbol (expected Module:))

我正在尝试将 friendlyid 添加到我的应用程序,但在我设置完所有内容后出现以下错误:

TypeError 错误的参数类型 Symbol expected Module

我将 extend :FriendlyIdfriendly_id :wine_name, use: :slugged 插入到我的模型中。我也尝试使用 slug 而不是 slugged 但这没有用。

我尝试了不同的路径,但似乎都行不通

这是我的wines_controller

class WinesController < ApplicationController
  before_action :set_wine, except: [:index, :new, :create]
  before_action :authenticate_user!, except: [:show]
  before_action :is_authorised, only: [:details, :pricing, :description, :photo_upload, :more_details, :sets, :location, :update]

  def index
    @wines = current_user.wines
  end

  def new
    @wine = current_user.wines.build
    redirect_to root_path unless current_user.admin?
  end

  def create
    @wine = current_user.wines.build(wine_params)
    if @wine.save
      redirect_to details_wine_path(@wine), notice: "Saved..."
    else
      flash[:alert] = "Something went wrong..."
      render :new
    end
  end

  def show
    @photos = @wine.photos
    @guest_reviews = @wine.guest_reviews
  end

  def details
  end

  def pricing
  end

  def description
  end

  def photo_upload
    @photos = @wine.photos
  end

  def more_details
  end

  def sets
  end

  def location
  end

  def update

    new_params = wine_params
    new_params = wine_params.merge(active: true) if is_ready_wine

    if @wine.update(wine_params)
      flash[:notice] = "Saved..."
    else
      flash[:alert] = "Something went wrong..."
    end
    redirect_back(fallback_location: request.referer)
  end

  def preload
    today = Date.today
    # Reservations greater than today (upcoming reservations)
    reservations = @wine.reservations.where("start_date >= ?", today)

    render json: reservations
  end


  private
  def set_wine
    @wine = Wine.friendly.find(params[:id])
  end
  # Authorize user (current_user == ID 1)
  def is_authorised
    redirect_to root_path, alert: "You don't have permission" unless current_user.id == @wine.user_id
  end

  def is_ready_wine
    !@wine.active && !@wine.price.blank? && !@wine.base_price.blank? && !@wine.wine_name.blank? && !@wine.summary.blank? && !@wine.photos.blank? && !@wine.alcohol.blank? && !@wine.filling.blank? && !@wine.in_stock.blank? && !@wine.address.blank?
  end

  def wine_params
    params.require(:wine).permit(:wine_type, :wine_color, :wine_art, :alcohol, :wine_name, :summary, :address, :is_1, :is_3, :is_6, :is_12, :filling, :base_price, :price, :in_stock, :year, :active)
  end
end

我假设您在 Wine 模型中使用了 FriendlyId,错误就在那里。

它可能看起来像

class Wine < ApplicationRecord
  extend :FriendlyId
  # ...
end

错误说它期待一个模块但收到了一个符号,从 FriendlyId

中删除 :
class Wine < ApplicationRecord
  extend FriendlyId
  # ...
end