module SudoAttributes::InstanceMethods
Public Instance Methods
sudo_assign_attributes(attributes)
click to toggle source
Used by sudo_attributes internally as a common API between Rails 3 and 3.1
# File lib/sudo_attributes.rb, line 94 def sudo_assign_attributes(attributes) if respond_to? :assign_attributes assign_attributes(attributes, :without_protection => true) else self.send(:attributes=, attributes, false) end end
sudo_update_attributes(new_attributes)
click to toggle source
Updates attributes of a model, including protected ones, from the passed-in hash and saves the record. If the object is invalid, the saving will fail and false will be returned.
Example¶ ↑
# Updated protected attributes on an instance of User @user = User.find(params[:id]) @user.sudo_update_attributes(params[:user])
# File lib/sudo_attributes.rb, line 76 def sudo_update_attributes(new_attributes) sudo_assign_attributes(new_attributes) save end
sudo_update_attributes!(new_attributes)
click to toggle source
Updates its receiver just like sudo_update_attributes
but calls save!
instead of save
, so an exception is raised if the record is invalid.
Example¶ ↑
# Updated protected attributes on an instance of User @user = User.find(params[:id]) @user.sudo_update_attributes!(params[:user])
# File lib/sudo_attributes.rb, line 88 def sudo_update_attributes!(new_attributes) sudo_assign_attributes(new_attributes) save! end