How to find available methods in the Rails documentation?

I am new to Rails and I find it extremely opaque. I have a copy of the latest Agile Web Development with Rails, but I'm worried that without this book I would have been completely lost.

For example, following the example of a depot in a book, when it comes to adding validation to a model, you do

class Product < ActiveRecord::Base validates :title, :description, :image_url, :presence => true end 

It seems easy enough, except that without the AWDwR book, I would never have thought of that. There is nothing in the ActiveRecord :: Base documentation that mentions the validates method.

It seems to me that with Rails you simply must mysteriously know what methods are available at any time in the project. But if you do not know how you should know (except remembering a book with more than 500 pages)?

I can formulate the question differently: in my Product class, I have the validates method available to me. How is this method available for my product class? Even knowing that it is defined in ActiveModel :: Validations :: ClassMethods (I know this because I searched for it), I cannot understand how it was available for my Product class.

+4
source share
4 answers

Almost a year has passed, and now I can look back and say that the best resources that I have found for studying rails are Rails Guides at http://guides.rubyonrails.org/ . They link everything together very well, provide some examples, and give me an entry point to the API documentation (as opposed to accidentally randomly moving around, like it did when I first started).

0
source

I use http://railsapi.com/ on a daily basis, hope you find this useful as well!

+1
source

authoritative site too - http://api.rubyonrails.org

+1
source

Rails ActiveRecord supports introspection of columns and model methods, just use the following

 $ rails console 1.9.3> Product.columns 1.9.3> => [#<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x007fe853d2c1f0 @name="id", @sql_type="integer", @null=false, ... 1.9.3> Product.methods 1.9.3> => [:_validators, :before_add_for_memberships?, :before_add_for_memberships=, :before_add_for_memberships, :after_add_for_memberships?, ... 

This will theoretically allow you to discover likely methods (or columns) that may be of interest, and then you can use the sources of the API document mentioned in other answers.

+1
source

Source: https://habr.com/ru/post/1344533/


All Articles