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
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 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 :
586
591
587
592
```ruby
588
593
...
589
594
defdata
590
595
records.map do |record|
591
596
{
592
-
id: record.decorate.id,
593
-
first_name: record.decorate.first_name,
594
-
email: record.decorate.email
597
+
id:record.decorate.id,
598
+
first_name: record.decorate.link_to,
599
+
email:record.decorate.email,
595
600
# other attributes
601
+
dt_actions: record.decorate.dt_actions,
602
+
DT_RowId: record.id,
596
603
}
597
604
end
598
605
end
599
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