Skip to content

Helper methods

Mattia Roccoberton edited this page May 2, 2023 · 2 revisions

A support class can be provided for helper methods used to present the field values. Sample:

helper_class: AdminUtils

Then define the class:

classAdminUtils < TinyAdmin::Supportclass << selfdefcompact_datetime(input,options: [])input ? input.strftime(options&.first || '%Y-%m-%d %H:%M') : ''enddeflabel_for(value,options: [])options&.first ? ::I18n.t(options.first,default: value) : valueendendend

And to use an helper method:

sections:
- slug: postsname: Poststype: resourcemodel: Postindex:
attributes:
- id
- title
- created_at: compact_datetime, %Y%m%d

Clone this wiki locally