我试图在ARIA标签属性添加到一个链接,使其更容易获得。当我这样做,它按预期工作:
<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') %>
更新
在红宝石2.2现在你可以这样做:
'aria-label': get_aria_label_current_page('home')
至少Rails的5.2的这个工程太:
<%= link_to t('nav.projects'),
projects_path,
class: is_active('projects'),
aria: { label: get_aria_label_current_page('home') } %>
这类似于data-*
属性如何工作,这是很好的,因为你可以添加多个,并让他们分组。
这可能会在早期版本的工作,但我没有检查。