我正在尝试将aria-label属性添加到链接中,以使其更易于访问。当我这样做时,它可以按预期工作:

<a href="/" class="site-name <%= is_active('home') %>" aria-label="<%= get_aria_label_current_page('home') %>">Version Postman</a>

但这不是:
<%= link_to t('nav.projects'), projects_path, class: is_active('projects'), aria-label: get_aria_label_current_page('home') %>

我收到“意外的tLABEL”语法错误。有人知道出什么问题吗?

谢谢。

最佳答案

这是造成问题的标签上的破折号。尝试以下方法:

<%= link_to t('nav.projects'), projects_path, class: is_active('projects'), 'aria-label' => get_aria_label_current_page('home') %>

更新

在ruby 2.2中,您现在可以执行以下操作:
'aria-label': get_aria_label_current_page('home')

10-06 04:04
查看更多