Why can't I set boolean columns with update?

Posted by Benjamin Oakes on Stack Overflow See other posts from Stack Overflow or by Benjamin Oakes
Published on 2010-05-07T14:54:12Z Indexed on 2010/05/07 14:58 UTC
Read the original article Hit count: 381

I'm making a user administration page. For the system I'm creating, users need to be approved. Sometimes, there will be many users to approve, so I'd like to make that easy. I'm storing this as a boolean column called approved.

I remembered the Edit Multiple Individually Railscast and thought it would be a great fit. However, I'm running into problems which I traced back to ActiveRecord::Base#update.

update works fine in this example:

>> User.all.map(&:username)
=> ["ben", "fred"]
>> h = {"1"=>{'username'=>'benjamin'}, "2"=>{"username"=>'frederick'}}
=> {"1"=>{"username"=>"benjamin"}, "2"=>{"username"=>"frederick"}}
>> User.update(h.keys, h.values)
=> ...
>> User.all.map(&:username)
=> ["benjamin", "frederick"]

But not this one:

>> User.all.map(&:approved)
=> [true, nil]
>> h = {"1"=>{'approved'=>'1'}, "2"=>{'approved'=>'1'}}
>> User.update(h.keys, h.values)
=> ...
>> User.all.map(&:approved)
=> [true, nil]

Chaging from '1' to true didn't make a difference when I tested.

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord