У меня есть модель со следующим атрибутом:
has_rich_text :content
Однако я не могу сохранить в нее данные и ошибок нет. Я также не могу создавать новые записи с атрибутом содержимого.
В консоли:
irb(main):011:0> a.content
=> #<ActionText::RichText id: 6, name: "content", body: #<ActionText::Content " ">, record_type: "Section", record_id: 78730, created_at: "2020-04-26 22:32:27", updated_at: "2020-04-26 22:38:30">
irb(main):012:0> a.content = '<p>Hello World</p>'
irb(main):013:0> a.save
(0.2ms) BEGIN
Chapter Load (0.8ms) SELECT "chapters".* FROM "chapters" WHERE "chapters"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
ActiveStorage::Attachment Load (0.4ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 [["record_id", 6], ["record_type", "ActionText::RichText"], ["name", "embeds"]]
(0.2ms) COMMIT
=> true
irb(main):014:0> a.content
=> #<ActionText::RichText id: 6, name: "content", body: #<ActionText::Content " ">, record_type: "Section", record_id: 78730, created_at: "2020-04-26 22:32:27", updated_at: "2020-04-26 22:38:30">
irb(main):015:0> a.content.body
=> #<ActionText::Content " ">
irb(main):016:0> a.reload
Section Load (0.7ms) SELECT "sections".* FROM "sections" WHERE "sections"."id" = $1 LIMIT $2 [["id", "78730d87-8dfb-490a-a868-e96dc077b23e"], ["LIMIT", 1]]
=> #<Section id: "78730d87-8dfb-490a-a868-e96dc077b23e", title: "Introduction", position: 1, chapter_id: 1, created_at: "2020-04-26 22:29:57", updated_at: "2020-04-26 22:38:30">
irb(main):017:0> a.content
ActionText::RichText Load (1.2ms) SELECT "action_text_rich_texts".* FROM "action_text_rich_texts" WHERE "action_text_rich_texts"."record_id" = $1 AND "action_text_rich_texts"."record_type" = $2 AND "action_text_rich_texts"."name" = $3 LIMIT $4 [["record_id", 78730], ["record_type", "Section"], ["name", "content"], ["LIMIT", 1]]
=> #<ActionText::RichText id: 6, name: "content", body: #<ActionText::Content " ">, record_type: "Section", record_id: 78730, created_at: "2020-04-26 22:32:27", updated_at: "2020-04-26 22:38:30">
Затем, когда я пытаюсь создать новую запись, я получаю это:
ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_action_text_rich_texts_uniqueness")
DETAIL: Key (record_type, record_id, name)=(Section, 0, content) already exists.
Действие Текст из schema.rb
create_table "action_text_rich_texts", force: :cascade do |t|
t.string "name", null: false
t.text "body"
t.string "record_type", null: false
t.bigint "record_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
end
Любая помощь будет принята с благодарностью. Спасибо.