自定义HTML属性需要自定义帮助程序吗? [英] Custom HTML attribute requires a custom helper?

查看:112
本文介绍了自定义HTML属性需要自定义帮助程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个在输入中具有一些自定义数据属性的表单:

I'm trying to create a form with some custom data attributes on the inputs:

<input type="text" data-family="Dinosaurs">

这似乎是通过jquery轻松进行前端访问(哈哈!)的一种好方法:

This seemed like a nice clean way to have easy front-end access (haha!) with jquery:

$("[data-family='Dinosaurs']").doSomething()

问题是我无法获得Rails(3.0.3)来呈现该属性.

The problem is I can't get Rails (3.0.3) to render the attribute.

<%= f.text_field :question, :id=>"poll_question", :class=>"BigInput", :style=>"width:98%;", :attributes=>"data-submit_clear='1'" %>

我尝试了许多排列,但都无济于事,并且找不到如何执行此操作的示例.我是否需要修改text_field助手以支持任何自定义属性?

I've tried many permutations to no avail and can't find an example of how to do this. Do I need to modify the text_field helper to support any custom attributes?

推荐答案

糟糕.只是

<%= f.text_field :question, :id=>"poll_question", :class=>"BigInput", :style=>"width:98%;", 'data-submit_clear'=>'1' %>

这篇关于自定义HTML属性需要自定义帮助程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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