【发布时间】:2013-11-21 15:46:12
【问题描述】:
我有一个 Rails 应用程序,学生可以在其中申请雇主发布的项目。我有它,所以一个学生有_许多项目,一个项目属于_学生。问题是在学生被选中之前,该项目可能存在很长时间。我的意思是,在雇主按下视图中的雇用按钮之前,项目的 student_id 为 nil。一旦雇主按下“雇用”按钮,我就会尝试将项目的 student_id 设置为被雇用的学生。出于某种原因,我不能这样做。这是项目模型:
class Project < ActiveRecord::Base
belongs_to :student
belongs_to :employer
has_many :relationships
def change_it
self.student_id = self.relationships.where(:state => :active).first.student_id
self.relationships.each do |relationship|
if relationship.state != :active
relationship.deny_applicants
end
end
end
end
当我点击租用按钮时,它会像往常一样将我带到下一页,但是当我在控制台中检查项目的 student_id 时,它仍然是 nil。
我该如何解决这个问题?谢谢。
【问题讨论】:
-
有什么想法吗?我已经工作了几个小时 - 仍然无法正常工作。
标签: ruby-on-rails ruby-on-rails-4 rails-activerecord has-many belongs-to