Rails 5: FriendlyId TypeError (неправильный тип аргумента Symbol (ожидаемый модуль :)) - PullRequest
0 голосов
/ 02 ноября 2018

Я пытаюсь добавить friendlyid в свое приложение, после того, как я все настроил, я получаю следующую ошибку:

TypeError неправильный тип аргумента Символ ожидается Модуль

Я вставил extend :FriendlyId и friendly_id :wine_name, use: :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

1 Ответ

0 голосов
/ 02 ноября 2018

Я предполагаю, что вы используете FriendlyId в вашей Wine модели, ошибка там.

Это может выглядеть примерно так:

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

Ошибка говорит, что он ожидал модуль, но получил символ, удалите : из FriendlyId

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