Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add decorator for Legislation #6

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions app/admin/legislations.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 15 additions & 0 deletions app/decorators/legislation_decorator.rb
Original file line number Diff line number Diff line change
@@ -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