Hello All,
I am trying to update a protected attribute called 'picture'. I am forced (I think) to use the following technique.
#first find a record or object @user = User.find(:some_id_here) .. .. # then assign the new value to protected attribute like this @user.picture ="somenewpicture.jpg"
#and then update the object like this... @user.update_attributes(other_updated_attributes_hash)
But instead I would like the following technique to update the object and save to db.
@user = User.update(15, {:user_name => 'Samuel', :group => 'expert', :picture="somenewpicture.jpg"})
The above technique does not update the picture attribute in db because its protected attribute.
Is it possible to update the protected attributes using Class.update method??
Is it not inefficient to find first unnecessarily, the object (record) as in the first technique and then save back to db. This can be slower in case of large database, where we have to unnecessarily find a record even though we know the record which we want to update, and thus making unnecessary query to find a record.
Is there any efficient method to do this along with updating protected attributes?