0

I am interested in understanding how find_by_(column_name) works. How does Ruby on Rails dynamically define the method on calling find_by_id, find_by_name, etc?

1

1 Answer 1

2

This is the power of meta programmation in Ruby, and more specifically the method_missing method: https://ruby-doc.org/core-2.1.0/BasicObject.html#method-i-method_missing

When you call a method on an instance of a Class that is not defined in that class, the method_missing catches it and you can handle it there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.