Skip to content

Commit d85e1da

Browse files
committed
Update README [ci skip]
1 parent 4ea4df2 commit d85e1da

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,21 +583,46 @@ end
583583

584584
If you want to keep things tidy in the data mapping method, you could use
585585
[Draper](https://github.com/drapergem/draper) to define column mappings like below.
586-
On the long term it's much more cleaner than using `def_delegator` since decorators are reusable.
586+
On the long term it's much more cleaner than using `def_delegator` since decorators are reusable so we strongly recommand you to
587+
use Draper decorators. It will help you to keep your DataTables class small and clean and keep focused on what they should do (mostly) : filtering records ;)
588+
The presentation layer should rely on Decorators class.
589+
590+
Example :
587591

588592
```ruby
589593
...
590594
def data
591595
records.map do |record|
592596
{
593597
id: record.decorate.id,
594-
first_name: record.decorate.first_name,
598+
first_name: record.decorate.link_to,
595599
email: record.decorate.email,
596600
# other attributes
601+
dt_actions: record.decorate.dt_actions,
602+
DT_RowId: record.id,
597603
}
598604
end
599605
end
600606
...
607+
608+
class UserDecorator < ApplicationDecorator
609+
delegate :id, :first_name
610+
611+
def link_to
612+
h.link_to first_name, h.user_path(object)
613+
end
614+
615+
def email
616+
h.mail_to object.email
617+
end
618+
619+
def dt_actions
620+
links = []
621+
links << h.link_to 'Edit', h.edit_user_path(object) if h.policy(object).update?
622+
links << h.link_to 'Delete', h.user_path(object), remote: true if h.policy(object).destroy?
623+
h.safe_join(links, '')
624+
end
625+
end
601626
```
602627

603628

0 commit comments

Comments
 (0)