Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails decorator delegation with method missing
class << self
def method_missing(method, *args)
result = (method == :all) ? Account.scoped : Account.send(method, *args)
result.where(something: true).map { |a| self.new a }
rescue NoMethodError => e
if result.is_a? ActiveRecord::Relation
raise e
else
raise NoMethodError.new "Account.#{ method } did not return a relation", method, args
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.