I have model user.rb like below:
class User < ActiveRecord::Base
before_save :set_default
def set_default
self[:is_admin] || 0
self[:is_active] || 1
end
end
Now when i create u new user , it inserts is_admin = null , is_active = null . While when i update user and send parameters is_admin= true , is_active = true or whatever values it updates it correctly . I did some R&D and found that i should do the following
def set_default
self.is_admin || 0
self.is_active || 1
end
Now the case becomes totally alternate . Means now values are inserting correctly on creation . but updation makes no difference . I also tried it with the following
def set_default
self.is_admin ||= 0
self.is_active ||= 1
end
But still no help . Kindly explain what's going on . Any help will be appreciated .
self.is_admin]can you tell me what that square bracket does? and what should i google to get more info on that?