Here's a proposed patch to simplify HTML5 data attribute declaration:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5825-html5-data-attributes
Any comments?
As explained in the ticket:
Specifying HTML5 data attributes for tags could be more streamlined. Right now you would use string keys and repetition.
To create, for example, this:
<div class="user" data- location="{"city":"Chicago","state":"Illinois"}" data-name="Stephen" id="user_1">
You would do something like this:
div_for user, 'data-name' => user.name, 'data-location' => { city: user.city, state: user.state }.to_json do # ...
Here's a proposed simplification, using a single "data" node to define the attributes:
div_for user, data: { name: user.name, location: { city: user.city, state: user.state } } do # ...
Seeing as data attributes are accessed primarily by JavaScript (with libraries like jQuery already interpreting embedded JSON objects), it makes sense to convert objects to JSON automatically rather than create pseudo-nested attributes like "data-location-city" and "data- location-state".