Why can't I set boolean columns with update?
- by Benjamin Oakes
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?