Skip to content

Instantly share code, notes, and snippets.

@JeremiahChurch
JeremiahChurch / auto_decorate_associations.rb
Last active May 4, 2020 17:11
Draper Automatic association decoration
# Keeping track of associations in activerecord and then going over to draper decorators and adding new associations is
# something that I never much liked - multiple places meant a potential error.
# so here's an easy draper concern that keeps your draper decorators in sync with your underlying models.
# just `include AutoDecorateAssociations` on your decorators and you're done worrying about changing associations on your models.
# If you're working with a model that doesn't have a decorator - like papertrail then it can be easily excluded like :versions below.
module AutoDecorateAssociations
extend ActiveSupport::Concern
included do
@JeremiahChurch
JeremiahChurch / app-lib-subdomain_constraint.rb
Last active November 11, 2022 00:15
Custom Subdomains from Models in Rails & Rspec testing too
class SubdomainConstraint
# used in routes to generate subdomains
# note there is a cache buster in company.rb in case the subdomain is updated - `reload_routes`
# update it if we write any additional cache entries here
RESERVED_SUB_DOMAINS = %w[
www app admin test staging help support wwww cdn owner media intercom mail r _domainkey blog webhooks webhook
hooks api api-test api-staging referral outbound mail webmail w3 mailboxes io heroku inbound google search
].freeze