Rails - how to add an attribute to a text_field_tag

Viewed 5527

I want to add a data attribute to a text field tag

<%= text_field_tag(:address) %>

which produces

<input id="address" type="text" name="address") %>

to make it have the HTML of

<input id="address" type="text" name="address" data-clob="ccc") %>

so I tried

<%= text_field_tag(:address, data:{clob: 'ccc'}) %>

but it was added as the actual value instead of an attribute, i.e.

<input id="address" type="text" value="{:data=>{:clob=>"ccc"}}" name="address"></input>

even though for a text field label I had used

<%= label_tag(:address, t("ui.reservations.between_now_and_param", 
param: @start_date.strftime(    time_format)), data:{blob: 'bbb'})%>

as detailed in How to add HTML5 data- attributes to a rails form label tag?

How can I add it as an attribute?

1 Answers
Related