Skip to content

Instantly share code, notes, and snippets.

@thiagoa
Created December 19, 2016 13:09
Show Gist options
  • Save thiagoa/40194e3335cb6b4cae0dc4c89649419f to your computer and use it in GitHub Desktop.
Save thiagoa/40194e3335cb6b4cae0dc4c89649419f to your computer and use it in GitHub Desktop.
module Imageable
# When including this module, this hook is called
# by Ruby with the included module/class
def self.included(model_class)
model_class.has_many :images
end
def main_image
images.find { |image| image.kind == 'main_image' }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment