Skip to content

Instantly share code, notes, and snippets.

@razorcd
Last active August 29, 2015 14:12
Show Gist options
  • Save razorcd/712174d56c0bdc38b671 to your computer and use it in GitHub Desktop.
Save razorcd/712174d56c0bdc38b671 to your computer and use it in GitHub Desktop.
<!--
HTML5 data- attributes using RESTful approach
HTML5 specifies extensible attributes like data-foo=“bar” (or as in Twitter Bootstrap data-toggle=“modal”), which poses two problems for Rails.
First, if you’re using symbol notation in link_to (for instance) to specify attributes, this fails (dash is not a valid symbol character), so:
-->
<% link_to('Edit', '../main.html', :class => "btn", :data-toggle => "modal") %> <!-- INVALID!! -->
<!--
There are two solutions:
1. put the symbols in quotes,
2. use the special ":data" hash
-->
<% link_to('Edit', '../main.html', :class => "btn", "data-toggle" => "modal") %> <!-- SOLUTION 1 -->
<% link_to('Edit', '../main.html', :class => "btn", :data => {:toggle => "modal"}) %> <!-- SOLUTION 2 -->
<!-- Credit goes to: To Harrison JR (http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to#1286-HTML5-data-attributes-using-RESTful-approach) -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment