The issue, of course, is that ruby symbols don't like hyphens. So something like this obviously won't work:
content_tag(:div, "Some Text", :id => "foo", :data-data_attr => some_variable)
One option is to use a string rather than a symbol:
content_tag(:div, "Some Text", :id => "foo", 'data-data_attr' => some_variable)
Or I could just interpolate:
"<div id='foo' data-data_attr='#{some_variable}'>Some Text</div>".html_safe
I sorta prefer the later but both seem a little gross. Anyone know of a better way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…