Skip to content

Commit 2742292

Browse files
Params are optional in in apply_sort
1 parent 5efd8e3 commit 2742292

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ You can use `apply_sort` in your controller :
7272
class ContactsController < ApplicationController
7373
def index
7474
@contacts = Contact.apply_sort(params)
75+
@contacts = Contact.apply_sort # to only apply default sort
7576
end
7677
end
7778
```

lib/jsonapi/scopes/sorts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def sortable_fields(*fields)
1818
@sortable_fields = fields
1919
end
2020

21-
def apply_sort(params, options = { allowed: [], default: {} })
21+
def apply_sort(params = {}, options = { allowed: [], default: {} })
2222
fields = params.dig(:sort)
2323

2424
allowed_fields = [options[:allowed]].flatten.presence || @sortable_fields

0 commit comments

Comments
 (0)