For anyone stumbling across this in 2016 using either the newer version of Rails (4) or the newer version of Parsley (2) here is what you'll need to do:
First of all to activate parsley with data attributes in the new version you add data-parsley-validate
now instead of the data-validate="parsley"
from version 1 of Parsley. Now lets get that to work with rails form_for
.
Even if you're not using parsley, this is how to insert a data attribute in Rails 4.
<%= form_tag '/login', :"data-parsley-validate" => '' do %>
<!-- inputs -->
<% end %>
So basically the difference is not using the html=>{}
hash. I tried that to see if that trick would work and at least for me my markup looked like this:
<form action="/login" method="post" html="{:data-parsley-validate}">
<!-- inputs -->
</form>
But by simply putting the data attribute directly in there as a symbol with an empty string as the corresponding value and it worked perfectly. This is the markup I received.
<form action="/login" method="post" data-parsley-validate>
<!-- inputs -->
</form>
In other words its perfect. So thats how to use Rails 4 to get data attributes in your form_tag
.