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 aboutupdatemethod 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!
You probably can’t find any good documentation about
ActiveRecord::Base#updatebecause 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::Relationwhich can be seen inrails/activerecord/lib/active_record/relation.rb.rails/activerecord/lib/active_record.rbcontains all theautoloads forActiveRecordwhich includes:Relation.The documentation for
ActiveRecord::Relation#updateis as follows: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 (
::Baseand::Relation) and gives you details about each and what version of Rails each are used in.