Module: Presenters::StandardOperationsForRecord
- Extended by:
- ActiveSupport::Concern
- Included in:
- CatalogItemPresenter, CatalogPresenter, DeliveryPresenter, ExportedCatalogItemPacketPresenter, OrderPresenter
- Defined in:
- app/concerns/presenters/standard_operations_for_record.rb
Overview
ActiveSupport::Concern mixin: standard operations for record.
Instance Method Summary collapse
- #audit_button ⇒ Object
- #created_at ⇒ Object
-
#destroy_record_button(record, options = {}) ⇒ Object
Renders a destroy button for a record assuming standard rails routing practices and bootstrap styles.
- #destroy_record_link(record, options = {}) ⇒ Object
-
#edit_record_button(record, options = {}) ⇒ Object
Renders an edit button for a record assuming standard rails routing practices and bootstrap styles.
- #edit_record_link(record, options = {}) ⇒ Object
- #updated_at ⇒ Object
Instance Method Details
#audit_button ⇒ Object
62 63 64 65 66 |
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 62 def return if r.blank? h.(r) end |
#created_at ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 44 def created_at begin return unless r.created_at rescue StandardError false end h.render_date(r.created_at) end |
#destroy_record_button(record, options = {}) ⇒ Object
Renders a destroy button for a record assuming standard rails routing
practices and bootstrap styles
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 10 def (record, = {}) return unless h.can?(:destroy, record) .reverse_merge!({ class: 'btn btn-danger', data: { turbo_confirm: "This will delete the #{record.class.name.humanize}, are you sure?" } }) destroy_record_link record, end |
#destroy_record_link(record, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 22 def destroy_record_link(record, = {}) = .dup data = ([:data] || {}).dup data[:turbo_method] ||= :delete data[:turbo_confirm] ||= data.delete(:confirm) if data[:confirm] [:data] = data h.link_to 'Delete', h.polymorphic_path(record), ** end |
#edit_record_button(record, options = {}) ⇒ Object
Renders an edit button for a record assuming standard rails routing
practices and bootstrap styles
33 34 35 36 37 38 |
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 33 def (record, = {}) return unless h.can?(:update, record) [:class] ||= 'btn btn-outline-primary' edit_record_link record, end |
#edit_record_link(record, options = {}) ⇒ Object
40 41 42 |
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 40 def edit_record_link(record, = {}) h.link_to 'Edit', h.polymorphic_path(record, action: :edit), ** end |
#updated_at ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'app/concerns/presenters/standard_operations_for_record.rb', line 53 def updated_at begin return unless r.updated_at rescue StandardError false end h.render_date(r.updated_at) end |