Module: Gridy::ViewHelpers

Includes:
Pagy::Frontend, Turbo::FramesHelper
Defined in:
lib/gridy/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#gridy_search_urlObject



9
10
11
12
13
14
15
# File 'lib/gridy/view_helpers.rb', line 9

def gridy_search_url
  uri = URI(request.url)
  params = Rack::Utils.parse_query(uri.query)
  params.delete("page")
  uri.query = params.to_query
  uri.to_s
end

#gridy_table_header(field, title = nil, sortable: false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gridy/view_helpers.rb', line 17

def gridy_table_header(field, title = nil, sortable: false)
  unless sortable
    return title || field.to_s.titleize
  end

  uri = URI(request.url)
  params = Rack::Utils.parse_query(uri.query)

  if params["sort"].to_s.start_with?(field.to_s)
    icon = params["sort"].to_s.end_with?("asc") ? "" : ""
  else
    icon = ""
  end

  params["sort"] = "#{field} #{params["sort"] == "#{field} asc" ? "desc" : "asc"}"
  uri.query = params.to_query

  link_to(uri.to_s, class: "") do
    (:span, "#{title || field.to_s.titleize} #{icon}".html_safe)
  end
end