0

In the below form I need the :data_progression to be data-progression in the HTML.

Hyphen instead of underscore.

How do I achieve this? Have looked around but haven't come across a clear explanation.

<%= form_for @contact_form, :html => {:id => "myform"} do |f| %>
<p>
<%= f.text_field :name, :class => "first_name", :id => "first_name", :data_progession => "" %>Name  &amp Number<br />
<%= f.text_field :email, :class => "email" %>E-mail<br />
<%= f.text_area :message, :class => "message", :placeholder => "Your Message Here*" %><br />
<%= f.submit "Send", :class => "button" %>
</p>
<% end %>
bad_coder
  • 11,289
  • 20
  • 44
  • 72
user2085143
  • 4,162
  • 7
  • 39
  • 68

2 Answers2

2

When you use data attributes in a Rails helper, the current preferred method is to use a data hash as so:

<%= f.text_field :name, :class => "first_name", :id => "first_name", :data => { :progression => "" } %>Name  &amp Number<br />

That should give you the hyphen like you desire. Also, anything in the data hash should convert to hyphens to conform with html customs.

evanbikes
  • 4,131
  • 1
  • 22
  • 17
1

I hope I'm not mistaken (didn't test myself now), but it should be e.g.

f.text_field :name, :class => "first_name", :id => "first_name", :data => { :progession => "" }

Tomáš Dundáček
  • 1,060
  • 9
  • 8