我有两个模型slide
和cards
。
class Slide < ApplicationRecord
has_many :cards,-> { order(:position) },dependent: :destroy
accepts_nested_attributes_for :cards,reject_if: proc { |attr| attr['title'].blank?}
end
和SlideController
def create
@slide = Slide.new(get_params)
@slide.save
end
当我尝试用卡片保存幻灯片时,出现错误
@messages = {:“ cards.slide” => [“必须存在”]},@details = {:“ cards.slide” => [{:error =>:blank}]}>
如果我从-> { order(:position) }
中删除了has_many
,那么一切正常。如果我正确,则在提交嵌套属性时会首先创建幻灯片,这是怎么回事?