[skip ci] Change associations `sort_link` docs

and provide the 'SQL string' version as an alternative in case of
difficulty.

This commit is in response to some users over time stating that the
docs were incorrect. I haven't been able to reproduce the issue. Let's
see what user feedback comes in. Closes #468, #450 and #431.
This commit is contained in:
Jon Atack 2015-08-21 11:54:20 +02:00
parent 448c392e07
commit 9a22ae4506
1 changed files with 6 additions and 6 deletions

View File

@ -335,15 +335,15 @@ end
...
<%= content_tag :table do %>
<%= content_tag :th, sort_link(@q, :last_name) %>
<%= content_tag :th, sort_link(@q, 'departments.title') %>
<%= content_tag :th, sort_link(@q, 'employees.last_name') %>
<%= content_tag :th, sort_link(@q, :department_title) %>
<%= content_tag :th, sort_link(@q, :employees_last_name) %>
<% end %>
```
Please note that in a sort link, the association is expressed as an SQL string
(`'employees.last_name'`) with a pluralized table name, instead of the symbol
`:employee_last_name` syntax with a class#underscore table name used for
Ransack objects elsewhere.
If you have trouble sorting on associations, try using an SQL string with the
pluralized table (`'departments.title'`,`'employees.last_name'`) instead of the
symbolized association (`:department_title)`, `:employees_last_name`).
### Using Ransackers to add custom search functions via Arel