Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple monkey patch for decent_exposure's nu_nu branch to add automatic decoration of singular resources. Throw this in config/initializers and monkey patch your way to victory! Assumes a module like the one included.
class DecentExposure::ActiveRecord::Finder
def decorated_singular_resource
singular_resource.extend("#{singular_resource.class.name}Decorator".constantize)
rescue NameError
singular_resource
end
def resource
if plural?
collection_resource
else
decorated_singular_resource
end
end
end
module UserDecorator
def full_name
[first_name, last_name].join(' ')
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.