-
-
Save marcamillion/4316662 to your computer and use it in GitHub Desktop.
This allows you to do something like this: Say Advertiser is an assoc on banner, you could do something like: Advertiser.first.featured_banners And if you later add a banner type named 'Awesome' you could immediately call Advertiser.first.awesome_banner without writing new code in the model.
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
#Here's what I'm using. Maybe you could adapt it to your case. I have this on a Message model. | |
def method_missing(method_name, *args, &block) | |
if method_name =~ /(.*)_recipients$/ | |
self.correspondences.where('recipient_type = ?', $1.to_s.humanize) | |
.collect{ |c| c.recipient }.flatten.uniq | |
else | |
super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment