2012-05-01 41 views
2

我試圖做到這一點的幫助:如何將數據屬性添加到R​​ails radio_button?

def radio_button_by_code(da_form, da_field, product_id, option_code) 
    txt = Product.find(product_id).options.find_by_code(option_code).title 
    btn = da_form.radio_button(da_field, txt, :data-product-id => product_id) 
    "<label>#{btn} #{txt}</label>".html_safe 
    end 

但是,如果我這樣做,我總是得到一個未定義的局部變量或方法'產品」的錯誤。

如果我刪除:data-product-id => product_id部分,那麼它會正確輸出單選按鈕。

如何將數據屬性添加到radio_button?

+0

什麼,如果你這樣做:':「數據產品ID」' – apneadiving

回答

8

試試這個: "data-product-id" => product_id

+2

這是我在評論 – apneadiving

+0

不好意思寫,我只看到了後,你的評論。 –

+0

沒問題和+1 :) – apneadiving

相關問題