Skip to content

Instantly share code, notes, and snippets.

@justinfrench
Created May 31, 2011 01:27
Show Gist options
  • Save justinfrench/999731 to your computer and use it in GitHub Desktop.
Save justinfrench/999731 to your computer and use it in GitHub Desktop.
Did you know there's a less painful way to do data attributes in Rails?
# This has very little win:
<%= content_tag(:p, "Foo", "data-bah" => "...", "data-baz" => "...") %>
# Some chumps make it even more noisy:
<%= content_tag(:p, "Foo", :"data-bah" => "...", :"data-baz" => "...") %>
# I was going to patch Rails to convert :data_bah to "data-bah"
<%= content_tag(:p, "Foo", :data_bah => "...", :data_baz => "...") %>
# But they already do this:
<%= content_tag(:p, "Foo", :data => {:bah => "...", :baz => "..."}) %>
# Good enuff, thankz Railz!!!!!!!!
@benhoskings
Copy link

# Looks even better with 1.9 hashes :)
<%= content_tag(:p, "Foo", data: {bah: "...", baz: "..."}) %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment