我的模型中有一个属性,该属性存储为文本,但被解释为有理数。我有这个方法来处理:
def start
read_attribute(:start).to_r
end
当我将start
属性设置为新值时,start_was
辅助方法返回一个字符串,而不是一个有理数,但在我这样做之前,它会返回正确的值。为什么?
Loading development environment (Rails 3.2.8)
1.9.3p194 :001 > d = Day.find(55)
Day Load (8.7ms) SELECT "days".* FROM "days" WHERE "days"."id" = ? LIMIT 1 [["id", 55]]
=> #<Day id: 55, date: "2012-03-30", start: "1/2", finish: "2/2", created_at: "2012-09-18 15:16:42", updated_at: "2012-09-19 08:20:41", day_year_id: 1>
1.9.3p194 :002 > d.start_was
=> (1/2)
1.9.3p194 :003 > d.start=0
=> 0
1.9.3p194 :004 > d.start_was
=> "1/2"