Change docs to use update instead of update_attributes

上级 1f3a1fed
...@@ -41,7 +41,7 @@ def initialize(param) # :nodoc: ...@@ -41,7 +41,7 @@ def initialize(param) # :nodoc:
# permitted.class # => ActionController::Parameters # permitted.class # => ActionController::Parameters
# permitted.permitted? # => true # permitted.permitted? # => true
# #
# Person.first.update_attributes!(permitted) # Person.first.update!(permitted)
# # => #<Person id: 1, name: "Francesco", age: 22, role: "user"> # # => #<Person id: 1, name: "Francesco", age: 22, role: "user">
# #
# It provides a +permit_all_parameters+ option that controls the top-level # It provides a +permit_all_parameters+ option that controls the top-level
...@@ -329,7 +329,7 @@ def each_element(object) ...@@ -329,7 +329,7 @@ def each_element(object)
# # into a 400 Bad Request reply. # # into a 400 Bad Request reply.
# def update # def update
# redirect_to current_account.people.find(params[:id]).tap { |person| # redirect_to current_account.people.find(params[:id]).tap { |person|
# person.update_attributes!(person_params) # person.update!(person_params)
# } # }
# end # end
# #
......
...@@ -101,9 +101,9 @@ module Helpers ...@@ -101,9 +101,9 @@ module Helpers
# and generate HTML accordingly. # and generate HTML accordingly.
# #
# The controller would receive the form data again in <tt>params[:person]</tt>, ready to be # The controller would receive the form data again in <tt>params[:person]</tt>, ready to be
# passed to <tt>Person#update_attributes</tt>: # passed to <tt>Person#update</tt>:
# #
# if @person.update_attributes(params[:person]) # if @person.update(params[:person])
# # success # # success
# else # else
# # error handling # # error handling
...@@ -897,7 +897,7 @@ def text_area(object_name, method, options = {}) ...@@ -897,7 +897,7 @@ def text_area(object_name, method, options = {})
# invoice the user unchecks its check box, no +paid+ parameter is sent. So, # invoice the user unchecks its check box, no +paid+ parameter is sent. So,
# any mass-assignment idiom like # any mass-assignment idiom like
# #
# @invoice.update_attributes(params[:invoice]) # @invoice.update(params[:invoice])
# #
# wouldn't update the flag. # wouldn't update the flag.
# #
...@@ -1569,7 +1569,7 @@ def label(method, text = nil, options = {}, &block) ...@@ -1569,7 +1569,7 @@ def label(method, text = nil, options = {}, &block)
# invoice the user unchecks its check box, no +paid+ parameter is sent. So, # invoice the user unchecks its check box, no +paid+ parameter is sent. So,
# any mass-assignment idiom like # any mass-assignment idiom like
# #
# @invoice.update_attributes(params[:invoice]) # @invoice.update(params[:invoice])
# #
# wouldn't update the flag. # wouldn't update the flag.
# #
......
...@@ -130,7 +130,7 @@ module FormOptionsHelper ...@@ -130,7 +130,7 @@ module FormOptionsHelper
# the user deselects all roles from +role_ids+ multiple select box, no +role_ids+ parameter is sent. So, # the user deselects all roles from +role_ids+ multiple select box, no +role_ids+ parameter is sent. So,
# any mass-assignment idiom like # any mass-assignment idiom like
# #
# @user.update_attributes(params[:user]) # @user.update(params[:user])
# #
# wouldn't update roles. # wouldn't update roles.
# #
......
...@@ -17,7 +17,7 @@ module ActionView ...@@ -17,7 +17,7 @@ module ActionView
# # controller # # controller
# def update # def update
# post = Post.find(params[:id]) # post = Post.find(params[:id])
# post.update_attributes(params[:post]) # post.update(params[:post])
# #
# redirect_to(post) # Calls polymorphic_url(post) which in turn calls post_url(post) # redirect_to(post) # Calls polymorphic_url(post) which in turn calls post_url(post)
# end # end
......
...@@ -143,7 +143,7 @@ def self.email ...@@ -143,7 +143,7 @@ def self.email
end end
x.report 'Resource#update' do x.report 'Resource#update' do
Exhibit.first.update_attributes(:name => 'bob') Exhibit.first.update(name: 'bob')
end end
x.report 'Resource#destroy' do x.report 'Resource#destroy' do
......
...@@ -58,7 +58,7 @@ class TooManyRecords < ActiveRecordError ...@@ -58,7 +58,7 @@ class TooManyRecords < ActiveRecordError
# It also allows you to update the avatar through the member: # It also allows you to update the avatar through the member:
# #
# params = { member: { avatar_attributes: { id: '2', icon: 'sad' } } } # params = { member: { avatar_attributes: { id: '2', icon: 'sad' } } }
# member.update_attributes params[:member] # member.update params[:member]
# member.avatar.icon # => 'sad' # member.avatar.icon # => 'sad'
# #
# By default you will only be able to set and update attributes on the # By default you will only be able to set and update attributes on the
......
...@@ -223,7 +223,7 @@ def update(attributes) ...@@ -223,7 +223,7 @@ def update(attributes)
alias update_attributes update alias update_attributes update
# Updates its receiver just like +update_attributes+ but calls <tt>save!</tt> instead # Updates its receiver just like +update+ but calls <tt>save!</tt> instead
# of +save+, so an exception is raised if the record is invalid. # of +save+, so an exception is raised if the record is invalid.
def update!(attributes) def update!(attributes)
# The following transaction covers any possible database side-effects of the # The following transaction covers any possible database side-effects of the
......
...@@ -2,7 +2,7 @@ class Hash ...@@ -2,7 +2,7 @@ class Hash
# Return a hash that includes everything but the given keys. This is useful for # Return a hash that includes everything but the given keys. This is useful for
# limiting a set of parameters to everything but a few known toggles: # limiting a set of parameters to everything but a few known toggles:
# #
# @person.update_attributes(params[:person].except(:admin)) # @person.update(params[:person].except(:admin))
def except(*keys) def except(*keys)
dup.except!(*keys) dup.except!(*keys)
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册