Skip to content

Commit a458c8f

Browse files
authored
Update README.md
1 parent 26c3a60 commit a458c8f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,25 @@ query parameters in your URLs.
467467
<% end %>
468468
```
469469

470+
You can also use `ransack_alias` for sorting.
471+
472+
```ruby
473+
class Post < ActiveRecord::Base
474+
belongs_to :author
475+
476+
# Abbreviate :author_first_name to :author
477+
ransack_alias :author, :author_first_name
478+
end
479+
```
480+
481+
Now, you can use `:author` instead of `:author_first_name` in a `sort_link`.
482+
483+
```erb
484+
<%= sort_link(@q, :author) %>
485+
```
486+
487+
Note that using `:author_first_name_or_author_last_name_cont` would produce an invalid sql query. In those cases, Ransack ignores the sorting clause.
488+
470489
### Search Matchers
471490

472491
List of all possible predicates

0 commit comments

Comments
 (0)