我可以将数字作为数据对象中的键传递吗?

时间:2015-07-21 10:27:29

标签: ruby-on-rails ruby

我使用ruby模板生成链接。这有效:

  <% link_to t('features.cta_link')+link_id('features'),
    data: { test: t('header.button') } do %>

但我想设置数据属性数据-2,所以我尝试了

  <% link_to t('features.cta_link')+link_id('features'),
    data: { 2: t('header.button') } do %>

然后我得到了

unexpected ':', expecting => ...ion', itemscope: '', data: { 2: t('header.button') } do ... ^

1 个答案:

答案 0 :(得分:2)

我需要使用常规语法:

{ 2 => t('header.button') }