rails, adding an undefined attribute to form_tag

2019-05-21 04:11发布

i was wondering how do you put a "data-provide" attribute inside a rails form_tag? the html output i would like is...

<input type="text" data-provide="typeahead">

however in a form_tag, i can't just do something like

<%= f.text_field :data-provide => "typehead" %>

how can i add an undefined attribute like that in a form tag? do i need to submit a hidden field or use another helper method? i was looking through the form_tag helper api and it doesn't seem like i can just define another attribute.

it seems like there an easy solution to this, but im not quite sure. help would be appreciated. thanks

1条回答
仙女界的扛把子
2楼-- · 2019-05-21 04:52

Use :data option with a hash:

<%= f.text_field :some_field, :data => {:provide => "typeahead"} %>
查看更多
登录 后发表回答