Custom HTML attribute requires a custom helper?

RSG picture RSG · Mar 5, 2011 · Viewed 20.3k times · Source

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

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

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

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

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

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?

Answer

RSG picture RSG · Mar 5, 2011

Oops. It's just

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