Routine.rbでローカリゼーションするためのRoutineやRoutineContentのようなモデルがあります
Class Routine < ActiveRecord::Base
has_many :routine_contents, dependent: :destroy
accepts_nested_attributes_for :routine_contents, reject_if: proc {|attributes| attributes['title'].empty?}
end
およびRoutinesContent
class RoutineContent < ActiveRecord::Base
belongs_to :routine
validates_presence_of :title
end
新しいRoutineアクションでは、言語のRoutineContenフィールドを設定します。1つのオブジェクトのタイトルが空の場合、このオブジェクトは拒否されます。
アクションを編集するとき、私はこれを行います
def set_routine_contents
contents = @routine.routine_contents.group_by {|content| content.lang}
if contents['ru'].nil?
@routine.routine_contents << RoutineContent.new(lang: 'ru')
end
if contents['en'].nil?
@routine.routine_contents << RoutineContent.new(lang: 'en')
end
end
このRailsINSERTINTOの後に終了し、テーブル内の空のオブジェクト、なぜですか?どうすれば無効にできますか?ありがとう