Ckt22
Ckt22

Reputation: 191

How to apply i18n to Rails Ransack's sort_link

I'm using Ranksack to make search and form sorting functionality. Among them, I found that I can use sort_link to sort the table by "Name":

<th scope="col"><%= sort_link(@query, :name) %></th>

However, I need to apply ``:name``` to i18n display. But if I apply it, the sorting function of sort_link is invalid:

<th scope="col"><%= sort_link(@query, t('task_name')) %></th>

How can I modify it to have both sorting and i18n functions?

Upvotes: 0

Views: 142

Answers (1)

Sampat Badhe
Sampat Badhe

Reputation: 9075

I think you need to pass label as a block - refer

<th scope="col">
  <%= sort_link(@query, :name) do %>
    <%= t('task_name') %>
  <% end %>
</th>

Upvotes: 1

Related Questions