jhund / filterrific

Filterrific is a Rails Engine plugin that makes it easy to filter, search, and sort your ActiveRecord lists.
http://filterrific.clearcove.ca
MIT License
910 stars 124 forks source link

5.2.4 release broke filterrific_sorting_link generation when current sorting is not present #216

Closed aditya-cherukuri closed 1 year ago

aditya-cherukuri commented 1 year ago

ruby: 3.1.3 rails 6.1.7.2

Saw that the 5.2.4 release was available but it broke some specs I have. When I tried it out on an internal feature it was actually broken.

It happens on initial page load when there are no sort options.

ActionView::Template::Error (undefined method `end_with?' for nil:NilClass

        current_sort_direction_indicator: (current_sorting.end_with?("_desc") ? opts[:descending_indicator] : opts[:ascending_indicator])
2:   <table class="table">
3:     <thead>
4:       <tr>
5:         <th><%= filterrific_sorting_link(@filterrific, :id) %></th>

From the looks of it I think it's this line of code:

current_sort_direction: if current_sorting
                                  current_sorting.end_with?("_desc") ? "desc" : "asc"
                                end,
current_sort_direction_indicator: (current_sorting.end_with?("_desc") ? opts[:descending_indicator] : opts[:ascending_indicator])

I can open a PR with the fix.

jhund commented 1 year ago

Thank you for the report and your contribution. Fix is merged and 5.2.5 is released.