Progress:
#== 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
Course:
# == 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
while I want to create a progress by
Course.first.progress.create(...)
It appears in rails console:
undefined method 'create' for nil:NilClass
Anyone get some ideas?Thanks
Try using
Course.first.create_progress(...); theprogress.createformat is for multiple associations such as ahas_many.