rails has_one создать ошибку - PullRequest
       0

rails has_one создать ошибку

0 голосов
/ 10 февраля 2012

Прогресс:

#== 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(...)
Появляется в консоли рельсов:
undefined method 'create' for nil:NilClass
Кто-нибудь есть идеи? Спасибо

1 Ответ

0 голосов
/ 10 февраля 2012

Попробуйте использовать Course.first.create_progress(...);формат progress.create предназначен для нескольких ассоциаций, таких как has_many.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...