Skip to content

Instantly share code, notes, and snippets.

@hannesfostie
Last active May 1, 2019 01:26
Show Gist options
  • Save hannesfostie/a5c7879803aa91c17c6e to your computer and use it in GitHub Desktop.
Save hannesfostie/a5c7879803aa91c17c6e to your computer and use it in GitHub Desktop.
class DnsRecord < ActiveRecord::Base
# This is a model using the default database
belongs_to :powerdns_record #...
before_create :create_in_powerdns
private
def create_in_powerdns
unless create_powerdns_record(attrs)
self.powerdns_error = "foo" # errors are returned from powerdns itself
false
end
end
end
class DnsTemplate < ActiveRecord::Base
# Another regular class
has_many :dns_template_records
def apply_to_domain(domain)
DnsTemplate.transaction do
dns_template_records.each { |rec| domain.dns_records.create!(rec.attributes) }
end
end
end
class PowerDNS::Record < PowerDNS::Base
# this uses a database on an entirely different server
# Nothing too fancy going on here
has_one :dns_record #...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment