Skip to content

Commit b986053

Browse files
committed
Fix build_query losing array param values on sort/paginate
Array#to_s returns inspect output (e.g. '["uuid"]'), which Rails re-parses as a literal string inside the array. Use Array(v) to handle both scalar and array values correctly.
1 parent e9679c1 commit b986053

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/ruby_ui/data_table/data_table_pagination.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def page_href(p)
4848
end
4949

5050
def build_query(hash)
51-
hash.map { |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&")
51+
hash.flat_map { |k, v|
52+
Array(v).map { |val| "#{CGI.escape(k.to_s)}=#{CGI.escape(val.to_s)}" }
53+
}.join("&")
5254
end
5355

5456
def prev_item

lib/ruby_ui/data_table/data_table_sort_head.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def sort_href
4444
end
4545

4646
def build_query(hash)
47-
hash.map { |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&")
47+
hash.flat_map { |k, v|
48+
Array(v).map { |val| "#{CGI.escape(k.to_s)}=#{CGI.escape(val.to_s)}" }
49+
}.join("&")
4850
end
4951

5052
def sort_icon

0 commit comments

Comments
 (0)