Class: TinyAdmin::Actions::Show

Inherits:
BasicAction show all
Defined in:
lib/tiny_admin/actions/show.rb

Instance Method Summary collapse

Methods inherited from BasicAction

#attribute_options

Methods included from Utils

#humanize, #params_to_s, #prepare_page, #to_class

Instance Method Details

#call(app:, context:, options:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tiny_admin/actions/show.rb', line 6

def call(app:, context:, options:)
  fields_options = attribute_options(options[:attributes])
  repository = context.repository
  record = repository.find(context.reference)
  prepare_record = ->(record_data) { repository.show_record_attrs(record_data, fields: fields_options) }
  attributes = {
    actions: context.actions,
    fields: repository.fields(options: fields_options),
    prepare_record: prepare_record,
    record: record,
    reference: context.reference,
    slug: context.slug,
    title: repository.show_title(record),
    widgets: options[:widgets]
  }

  prepare_page(Views::Actions::Show, slug: context.slug, attributes: attributes)
rescue Plugins::BaseRepository::RecordNotFound => _e
  prepare_page(options[:record_not_found_page] || Views::Pages::RecordNotFound)
end