2015-07-21 71 views
1

我使用紅寶石模板來生成鏈接。這工作:我可以傳遞一個數字作爲數據對象中的鍵嗎?

<% 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 ...^
+0

爲什麼要傳遞一個數字? – RSB

+1

嘗試'{「2」:...}' – Amadan

+0

沒有工作.... – Himmators

回答

2

我需要使用常規語法:

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

幾天前面臨同樣的問題,數據似乎不接受新的紅寶石語法 –

+0

@AndreyDeineko我不認爲'{2 :...}'是有效的ruby語法 – Stefan

+0

@Stefan,我很確定'2:'是無效的Ruby語法,我的意思是一般':'vs'=>'。 –

相關問題