2

I have a normal class (Event) where a boolean value is defined as

 attr_accessible :archived

and in the db schema is

t.boolean  "archived",                          :default => false

As such, the default method archived? is automatically defined.

After a debugging session I discovered this

>> a=Event.last
>> a.archived
false
>> a.archived=true
true
>> a.archived
true
>> a.archived?
false

Should't the last two values BOTH be true? What am I missing here?

Even this is not helping:

>> a.save
   (0.1ms)  begin transaction
   (45.2ms)  UPDATE "events" SET "archived" = 't', "updated_at" = '2012-12-10 06:31:57.410990' WHERE "events"."id" = 3
true
   (149.5ms)  commit transaction
>> a.archived?
false

Thank you in advance

piffy
  • 723
  • 2
  • 8
  • 21
  • what is your database engine ? – Fivell Dec 09 '12 at 23:50
  • What does attr_accessible have to do with the issue you're seeing? – Peter Brown Dec 09 '12 at 23:59
  • I wonder if it makes a difference that you haven't saved `a` yet. Before calling `a.archived?` what if you call `a.save` first? – agmin Dec 10 '12 at 00:00
  • 1
    I don't see the behavior you're claiming. What else is going on? – mu is too short Dec 10 '12 at 00:05
  • In agreement with @muistooshort; I'm seeing the same thing. What version of Ruby and Rails are you using? – samullen Dec 10 '12 at 01:55
  • the last code, I think it return false because you didn't save the object, so `a.archived?` still return false, if you run `a.save` then `a.archived?`, I think it will return `true`. – Thanh Dec 10 '12 at 02:25
  • To all: it' sqllite and Ruby 1.9.3 and Rails 3.2.3 To Beelrington: I don't knoe, I just tried to give all possible info I'll try to save when I'm back home – piffy Dec 10 '12 at 06:12

0 Answers0