diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 707b40654..0b3a8b785 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -2,7 +2,7 @@ module Admin class DomainsController < BaseController DEFAULT_VERSIONS_PER_PAGE = 10 - before_action :set_domain, only: %i[show edit update keep] + before_action :set_domain, only: %i[show edit update download keep] authorize_resource # rubocop:disable Metrics/MethodLength @@ -65,6 +65,11 @@ module Admin .per(DEFAULT_VERSIONS_PER_PAGE) end + def download + filename = "#{@domain.name}.pdf" + send_data @domain.as_pdf, filename: filename + end + def keep @domain.keep redirect_to edit_admin_domain_url(@domain), notice: t('.kept') diff --git a/app/models/domain.rb b/app/models/domain.rb index a8fc323a0..e75f5165c 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -743,6 +743,12 @@ class Domain < ApplicationRecord ] end + def as_pdf + domain_html = ApplicationController.render(template: 'domain/pdf', assigns: { domain: self }) + generator = PDFKit.new(domain_html) + generator.to_pdf + end + def registrant_name return registrant.name if registrant diff --git a/app/views/admin/domains/show.html.erb b/app/views/admin/domains/show.html.erb index 2b2835429..3055dbca5 100644 --- a/app/views/admin/domains/show.html.erb +++ b/app/views/admin/domains/show.html.erb @@ -6,11 +6,12 @@