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="{&quot;city&quot;:&quot;Chicago&quot;,&quot;state&quot;:&quot;Illinois&quot;}"
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".

---
Stephen

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to