niaomingjian niaomingjian - 1 month ago 7
Ruby Question

Where can I find the document of present? method of ActiveRecord_Relation in Rails?

I'm new to Rails. When I'm studying Rails, I come across some methods which I don't know how to use.
Then I try to Google, but the outcome is not very good.

For example, I defined a model

User
. In the
UsersController
, I defined
index
method. In this method, someone used the
@users.present?
method.
I'm not sure what it is. So I want to know how the official site says about it.

Where can I find the explanation of this method.

Could you tell me the way to study methods like this?

Answer

To see where specific method is defined, you can check it as follows:

@users.method(:present?)
#=> #<Method: User(Object)#present?>

This means, that method present? is defined in class Object.

Then, when you have a name of the class where method is defined, you just open documentation (either Ruby or Rails) and search for the method you want to learn about in corresponding class.

In your case, here is documentation for present? method.