method
update
v1.1.6 -
Show latest stable
-
1 note -
Class: ActiveRecord::Base
- 1.0.0 (0)
- 1.1.6 (26)
- 1.2.6 (0)
- 2.0.3 (0)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
update(id, attributes)
public
Finds the record from the passed id, instantly saves it with the passed attributes (if the validation permits it), and returns it. If the save fails under validations, the unsaved object is still returned.
The arguments may also be given as arrays in which case the update method is called for each pair of id and attributes and an array of objects is returned.
Example of updating one record:
Person.update(15, {:user_name => 'Samuel', :group => 'expert'})
Example of updating multiple records:
people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy"} } Person.update(people.keys, people.values)
Register or
log in
to add new notes.
mihserf -
August 17, 2008
2 thanks
collection update
in the FirmsController
@firm.people.update(params[:people].keys,params.values)
in the View
<% form_for(@firm) do |f| %>
<%= f.error_messages %> <%= f.text_field :name %> <%@firm.people.each do |person|%> <%fields_for "people[]", person do |pf|%> <%= pf.text_field :name %> <%end%> <%= f.submit "Save" %>
<%end%>