Home > Software engineering >  How to apply i18n to Rails Ransack's sort_link
How to apply i18n to Rails Ransack's sort_link

Time:04-07

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?

CodePudding user response:

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

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