rails,向form_tag添加一个未定义的属性 [英] rails, adding an undefined attribute to form_tag

查看:62
本文介绍了rails,向form_tag添加一个未定义的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在rails form_tag中放置数据提供"属性?我想要的html输出是...

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">

但是在form_tag中,我不能做类似的事情

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

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

如何在表单标签中添加未定义的属性?我是否需要提交隐藏字段或使用其他帮助方法?我一直在浏览form_tag帮助器api,但似乎无法定义另一个属性.

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

推荐答案

:data 选项与哈希一起使用:

Use :data option with a hash:

<%= f.text_field :some_field, :data => {:provide => "typeahead"} %>

这篇关于rails,向form_tag添加一个未定义的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆