method

update

Importance_2
v2.2.1 - Show latest stable - 1 note - Class: ActiveRecord::Base
update(id, attributes) public

Updates an object (or multiple objects) and saves it to the database, if validations pass. The resulting object is returned whether the object was saved successfully to the database or not.

Parameters

  • id - This should be the id or an array of ids to be updated.
  • attributes - This should be a Hash of attributes to be set on the object, or an array of Hashes.

Examples

  # Updating one record:
  Person.update(15, { :user_name => 'Samuel', :group => 'expert' })

  # Updating multiple records:
  people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } }
  Person.update(people.keys, people.values)
Show source
Register or log in to add new notes.
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%>