我試圖做到這一點的幫助:如何將數據屬性添加到Rails 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?
什麼,如果你這樣做:':「數據產品ID」' – apneadiving