Last active
December 11, 2015 09:19
-
-
Save moustafasamir/4579243 to your computer and use it in GitHub Desktop.
You’re not limited to the functionality that Rails automatically builds into association proxy objects. You can also extend these objects through anonymous modules, adding new finders, creators, or other methods. For example:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Customer < ActiveRecord::Base | |
has_many :orders do | |
def find_by_order_prefix(order_number) | |
find_by_region_id(order_number[0..2]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment