使用ActiveRecord模型访问实例变量

时间:2018-07-30 10:14:23

标签: ruby-on-rails ruby

遵循Rails测试处方。 Task表具有名为completed_at的列。为什么我只能用self.completed_at = date来写(completed_at = date失败),但是我可以在self方法中不用complete?来访问属性?

class Task < ApplicationRecord  
  belongs_to :project

  def mark_completed(date = Time.current)
    self.completed_at = date
  end

  def complete?
    completed_at.present?
  end
end

预先感谢

0 个答案:

没有答案