From 9c88e40b1b4598ba0e26b77fe1f49ae0f4bcbb90 Mon Sep 17 00:00:00 2001 From: Marek Kowalcze Date: Mon, 22 Jul 2019 10:10:31 +0200 Subject: [PATCH] add decorator for Legislation --- app/admin/legislations.rb | 9 ++++----- app/decorators/legislation_decorator.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 app/decorators/legislation_decorator.rb diff --git a/app/admin/legislations.rb b/app/admin/legislations.rb index 93ad87102..f08730029 100644 --- a/app/admin/legislations.rb +++ b/app/admin/legislations.rb @@ -1,4 +1,6 @@ ActiveAdmin.register Legislation do + decorate_with LegislationDecorator + permit_params :title, :description, :framework, :location_id, :law_id filter :title_contains, label: 'Title' @@ -11,12 +13,9 @@ config.batch_actions = false index do - column :title do |legislation| - link_to legislation.title, admin_legislation_path(legislation) - end + column :title, &:title_summary_link column :framework column :location - column :slug actions end @@ -26,7 +25,7 @@ f.inputs do f.input :title - f.input :description + f.input :description, as: :trix columns do column { f.input :location } column do diff --git a/app/decorators/legislation_decorator.rb b/app/decorators/legislation_decorator.rb new file mode 100644 index 000000000..dc3a7fa19 --- /dev/null +++ b/app/decorators/legislation_decorator.rb @@ -0,0 +1,15 @@ +class LegislationDecorator < Draper::Decorator + delegate_all + + TITLE_INDEX_LENGTH = 100 + + def title_summary_link + h.link_to model.title&.truncate(TITLE_INDEX_LENGTH), + h.admin_legislation_path(model), + title: model.title + end + + def framework + model.framework&.humanize + end +end