进展:
#== Schema Information
#
# Table name: progresses
#
# id :integer not null, primary key
# width :integer default(0)
# course_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Progress < ActiveRecord::Base
has_many:progress_comments
belongs_to:course
end
课程:
# == Schema Information
#
# Table name: courses
#
# id :integer not null, primary key
# courseName :string(50) not null
# place :string(100) not null
# startTime :datetime default(2012-02-10 00:39:52 UTC)
# endTime :datetime
# teacher :string(20) default("nil_teacher")
# reason :text not null
# upNum :integer default(0)
# downNum :integer default(0)
# day :integer not null
# school_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Course < ActiveRecord::Base
#attr_acessssible:
#validates :courseName, presence: true
has_many:remarks
has_many:reviews
has_one:progress
has_and_belongs_to_many:course_catagories
belongs_to:school
end
虽然我想通过
创造进步
Course.first.progress.create(...)
它出现在rails控制台中:
undefined method 'create' for nil:NilClass
有人得到一些想法吗?谢谢
答案 0 :(得分:0)
尝试使用Course.first.create_progress(...)
; progress.create
格式适用于多个关联,例如has_many
。