-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtable_helper.rb
37 lines (36 loc) · 1.07 KB
/
table_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module SortableBy
module TableHelper
# Build a table header for a model
#
# * path_helper: The helper method you want to use to generate URLs.
# * model: The class we should use for translations (optional)
# * permit: Array of request params that are forwarded to the sort links
#
# Example:
#
# <%= sortable_header :admin_users_path, model: User do |t| %>
# <%= t.sortable :name %>
# <%= t.sortable :email %>
# <%= t.header :last_login %>
# <th></th>
# <% end %>
#
# Header labels will be pulled from en.yml. To provide a different
# label pass the label: option
#
# Example:
#
# <%= t.header :name, label: 'Full Name' %>
#
def sortable_table_header(path_helper, model: nil, permit: [], icon: SortableBy.icon_strategy, &block)
header = SortableBy::TableHeader.new(
path_helper:,
model:,
params: params.permit(permit.concat(SortableBy.params_list)),
context: self,
icon:)
header.capture(block) if block
header.to_html
end
end
end