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?
Rails 3.1 ships with built-in helpers:
http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-tag
E.g.,