使用匹配创建学生都是模型,我想将学生的值存储在匹配中。应该如何解决这个问题?
我尝试了委托,但抛出了匹配为空的错误,有什么想法吗?谢谢!
用户模型:
class Student < ActiveRecord::Base
attr_accessible :name, :level
has_one :match
before_create :setup_match
def setup_match
self.create_match # create the match that belongs to this student
end
end
匹配型号:
class Match < ActiveRecord::Base
belongs_to :student
attr_accessible :initiated, :level
before_save :default_values
def default_values
# HERE is the problem
# Need to store student.name and student.level here, how?
self.initiated = student.name
self.level = student.level
end
end