레일을 사용하고 있습니다. 4.1.6 새 레코드를 만든 다음 저장하는 데 문제가 있습니다. 다음은 모델입니다.새 레코드에 새 레코드 추가
class Function < ActiveRecord::Base
belongs_to :theater
has_many :showtimes, dependent: :destroy
belongs_to :parsed_show
validates :theater, presence: :true
validates :date, presence: :true
end
class Theater < ActiveRecord::Base
has_many :functions, :dependent => :destroy
validates :name, :presence => :true
accepts_nested_attributes_for :functions
end
class Showtime < ActiveRecord::Base
belongs_to :function
validates :time, presence: true
validates :function, presence: true
end
showtime = Showtime.new time: Time.current
theater = Theater.first # read a Theater from the database
function = Function.new theater: theater, date: Date.current
function.showtimes << showtime
function.showtimes.count # => 0
왜 쇼 타임이 기능의 상영 시간에 추가되지 않습니까? 나중에 상영 시간표를 사용하여이 기능을 저장해야합니다.