How to add data attribute in Rails radio_button?

I am trying to do this in an assistant:

  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

But if I do this, I always get a local variable or an undefined method.

If I remove the component: data-product-id => product_id, it will issue the radio book correctly.

How to add data attribute to radio_button?

+3
source share
1 answer

Try the following: "data-product-id" => product_id

+9
source

All Articles