Skip to content

Instantly share code, notes, and snippets.

@mrsweaters
Created August 13, 2019 17:10
Show Gist options
  • Save mrsweaters/b8afac69ad25fd884f9f3c74f455060c to your computer and use it in GitHub Desktop.
Save mrsweaters/b8afac69ad25fd884f9f3c74f455060c to your computer and use it in GitHub Desktop.
Get organic samples and backfill from constants.
def self.sample_text(attr, scope: self, size: 3)
@organic = scope.last(size).map{|item| ActionController::Base.helpers.strip_tags(item.public_send(attr)) }.compact
defaults = "#{scope}::SAMPLE_#{attr.upcase}".constantize
(@organic + defaults).uniq.first(size)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment