我有一个无法解决的错误。
我有这些课程
class Content < ApplicationRecord
has_many :product_relations, as: :productable
has_many :products, through: :product_relations
end
class Product < ApplicationRecord
has_many :product_relations
has_many :contents, through: :product_relations, source_type: "Content", source: :productable
end
class ProductRelation < ApplicationRecord
belongs_to :product
belongs_to :content
belongs_to :productable, polymorphic: true
end
Rails 6升级后,我出现此错误:
pry(#<Admin::ContentsController>)> content.errors
=> #<ActiveModel::Errors:0x00007ff0c8ff4770
@base=
#<Review:0x00007ff0cec5f6e0
id: 35057,
name: "pippo",
type: "Review",
permalink: "pippo",
published_at: Mon, 01 Jun 2020 14:56:00 CEST +02:00,
body: "<p>sss</p>",
summary: "test",
aasm_state: "published",
author_id: 5,
created_at: Wed, 06 May 2020 17:54:26 CEST +02:00,
updated_at: Mon, 01 Jun 2020 15:00:08 CEST +02:00,
source_link: "",
source_name: "",
square_crop_img: nil,
impressions_count: 0,
brand_contacts_notified_at: nil,
main_image: "e571cc_server2.jpg",
b_f_notified_at: nil,
p_f_notified_at: nil,
follows_count: 1,
template: "large",
tsv: "'pipp':1 'sss':2",
pinned: false,
not_in_home: false,
sponsored: false,
no_adv: false,
presentation: "standard",
comments_count: 0,
brands_dday_companies_contacts_notified_at: nil,
brands_dday_companies_companies_notifiable_ids: [],
additional_html: "",
dmove: false,
tag_list: nil>,
@details={:product_relations=>[{:error=>:invalid}, {:error=>:invalid}, {:error=>:invalid}, {:error=>:invalid}, {:error=>:invalid}, {:error=>:invalid}]},
@messages={:product_relations=>["non è valido"]}>
基本上,我在内容验证错误。内容必须存在
"ActiveRecord::RecordInvalid: Validazione fallita: Content deve esistere
from /Users/scrivoaroby/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.2.2/lib/active_record/validations.rb:81:in `raise_validation_error'
我不明白为什么