How to find documentation for ActiveRecord::Base.update?

ruby, ruby-on-rails, ruby-on-rails-3

Solution

You probably can't find any good documentation about `ActiveRecord::Base#update` because the method has been deprecated since Rails version 2.3.8, according to APIdock..

The reason you can still use it is because it has been moved to `ActiveRecord::Relation` which can be seen in `rails/activerecord/lib/active_record/relation.rb`.

`rails/activerecord/lib/active_record.rb` contains all the `autoload`s for `ActiveRecord` which includes `:Relation`.

The documentation for `ActiveRecord::Relation#update` is as follows:

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 or an array of hashes.

==== Examples

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

# Updates multiple records 
people = { 1 => { "first_name" => "David" }, 2 => { "first_name" => "Jeremy" } }       
Person.update(people.keys, people.values)

EDIT: To answer your initial question, under most circumstances, doing a search on api.rubyonrails.org is enough to find the information you are looking for, as long as the information is up-to-date.

For potentially older API details, use apidock.com/rails. Doing a search there for 'update' actually shows both versions (`::Base` and `::Relation`) and gives you details about each and what version of Rails each are used in.

Problem

What is the process of finding the documentation for a method in Ruby/Rails api http://api.rubyonrails.org/ . Let's take method `ActiveRecord::Base.update` as an example. It is used in one of the railscasts. - There is no mention of update in the api doc for the class http://api.rubyonrails.org/classes/ActiveRecord/Base.html - There's nothing about `update` method in the source code for Base https://github.com/rails/rails/blob/0065f378262dc3f47880ce6211c7474bc7d11f0b/activerecord/lib/active_record/base.rb - In fact, I can't even find this method in any classes included in `ActiveRecord::Base`. I suspect this method is in ActiveRecord::Relation. However, I'm not sure. I'm a beginner in Ruby/Rails, and I come from Java world, where I would normally expect to see all methods (inherited as well) in a javadoc for the class. What is the most effective finding relevant documentation for mixed-in/inherited methods in case of Ruby/Rails? Thanks in advance!

Original source