You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-2Lines changed: 27 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -583,21 +583,46 @@ end
583
583
584
584
If you want to keep things tidy in the data mapping method, you could use
585
585
[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 :
587
591
588
592
```ruby
589
593
...
590
594
defdata
591
595
records.map do |record|
592
596
{
593
597
id: record.decorate.id,
594
-
first_name: record.decorate.first_name,
598
+
first_name: record.decorate.link_to,
595
599
email: record.decorate.email,
596
600
# other attributes
601
+
dt_actions: record.decorate.dt_actions,
602
+
DT_RowId: record.id,
597
603
}
598
604
end
599
605
end
600
606
...
607
+
608
+
classUserDecorator < ApplicationDecorator
609
+
delegate :id, :first_name
610
+
611
+
deflink_to
612
+
h.link_to first_name, h.user_path(object)
613
+
end
614
+
615
+
defemail
616
+
h.mail_to object.email
617
+
end
618
+
619
+
defdt_actions
620
+
links = []
621
+
links << h.link_to 'Edit', h.edit_user_path(object) if h.policy(object).update?
0 commit comments