SQLite3::ConstraintException: ограничение UNIQUE не удалось: action_text_rich_texts.record_type, action_text_rich_texts.record_id

Я не могу создать новый продукт и получаю эту ошибку, хотя product.valid? = true:

ActiveRecord::RecordNotUnique in Admin::ProductsController#create
SQLite3::ConstraintException: UNIQUE constraint failed: action_text_rich_texts.record_type, action_text_rich_texts.record_id, action_text_rich_texts.name

Не знаю почему. Вот схема моего продукта:

create_table "products", force: :cascade do |t|
    t.string "code"
    t.integer "real_price"
    t.integer "sale_price"
    t.integer "remaining_amount"
    t.string "title"
    t.text "description"
    t.text "detail"
    t.string "seo_title"
    t.string "seo_keyword"
    t.string "seo_description"
    t.integer "product_category_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["code"], name: "index_products_on_code", unique: true
    t.index ["product_category_id"], name: "index_products_on_product_category_id"
    t.index ["title"], name: "index_products_on_title", unique: true
  end

А вот и моя модель продукта:

class Product < ApplicationRecord
  belongs_to :product_category
  has_many_attached :images
  has_rich_text :detail

  validates :code, :title, presence: true
  validates :code, :title, uniqueness: { case_sensitive: false }
end

А вот и мой admin/products_controller.rb

class Admin::ProductsController < AdminController
  ...   
  def create
    @product = Product.new(product_params)
 
    if @product.save
      redirect_to  
    else
      render 'new'
    end
  end

  private

  ...

  def product_params
    params.require(:product).permit(:code, :real_price, :sale_price, :remaining_amount,
                                    :title, :description, :detail, :seo_title, :seo_keyword, :seo_description,
                                    :product_category_id, images: [])
  end
end

Пожалуйста, помогите мне исправить эту ошибку!

0 ответов

Другие вопросы по тегам