Module: NtiReceiptBuilder::TemplatesController
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/nti_receipt_builder/templates_controller.rb
Overview
The builder's actions, for inclusion in a host controller that owns routing, authorization and tenancy.
class Partner::ReceiptTemplatesController < PartnerController
include NtiReceiptBuilder::TemplatesController
private
def receipt_owner = current_account
end
Every query runs through receipt_owner, so the tenant boundary stays visible in host
code rather than in a configured lambda. Hosts may override any action or navigation
hook — a method defined in the including class wins over the one mixed in here.
Constant Summary collapse
- VIEW_PREFIX =
'nti_receipt_builder/templates'
Instance Method Summary collapse
-
#_prefixes ⇒ Object
Append the gem's view prefix so bare
render :editresolves to the engine's templates. - #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #new ⇒ Object
- #preview ⇒ Object
- #print ⇒ Object
- #render_preview ⇒ Object
- #set_default ⇒ Object
- #update ⇒ Object
Instance Method Details
#_prefixes ⇒ Object
Append the gem's view prefix so bare render :edit resolves to the engine's templates.
The host's own prefixes stay first, so dropping a receipt_templates/edit.html.erb into the
host shadows the gem's copy without any configuration.
31 32 33 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 31 def _prefixes @_prefixes ||= super + [VIEW_PREFIX] end |
#create ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 39 def create form = TemplateForm.new(receipt_template_params) unless form.valid? @errors = form.errors. @receipt_template = receipt_templates.new(default_template_attributes) return render_create_failure end @receipt_template = receipt_templates.new(form.attributes) if @receipt_template.save redirect_to after_create_path(@receipt_template), notice: 'Receipt template created! Now build your layout.' else @errors = @receipt_template.errors. render_create_failure end end |
#destroy ⇒ Object
73 74 75 76 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 73 def destroy @receipt_template.destroy redirect_to after_destroy_path, notice: 'Receipt template deleted!' end |
#edit ⇒ Object
59 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 59 def edit; end |
#new ⇒ Object
35 36 37 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 35 def new @receipt_template = receipt_templates.new(default_template_attributes) end |
#preview ⇒ Object
78 79 80 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 78 def preview @render_result = Renderer.new(template: @receipt_template).call end |
#print ⇒ Object
100 101 102 103 104 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 100 def print @render_result = Renderer.new(template: @receipt_template).call render :print, layout: false end |
#render_preview ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 82 def render_preview form = TemplateForm.new(receipt_template_params) @draft = @receipt_template.dup @draft.assign_attributes(form.attributes.except(:lock_version)) if !form.valid? @render_result = nil @draft_errors = form.errors. elsif @draft.valid? @render_result = Renderer.new(template: @draft).call @draft_errors = [] else @render_result = nil @draft_errors = @draft.errors. end end |
#set_default ⇒ Object
106 107 108 109 110 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 106 def set_default SetDefault.new(template: @receipt_template).call redirect_to after_set_default_path, notice: 'Default receipt template updated!' end |
#update ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/concerns/nti_receipt_builder/templates_controller.rb', line 61 def update form = TemplateForm.new(receipt_template_params) if form.valid? persist_update(form) else @errors = form.errors. end render :update, status: @errors.empty? ? :ok : :unprocessable_content end |