at.
at.

Reputation: 52500

Form input type="date" in Ruby on Rails

I want to have a date input for a form. I know this only works in some browsers:

<input type="date" name="birth_day"/>

Is there a convenient method for this in Ruby on Rails? The documentation for the various form elements list many other input types, but I don't see anything for dates:

I know about date_select, that's not what I want. I want the above HTML output. I'm using Ruby on Rails 3.2.13. Is there possibly a date_field in Ruby on Rails 4? Or another way to do this?

Upvotes: 12

Views: 26377

Answers (2)

kanga
kanga

Reputation: 379

For older versions of Rails I believe you can use:

.text_field(type: 'date')

Upvotes: 5

Pigueiras
Pigueiras

Reputation: 19356

You can see the lastest docs that the date_field helper provide that. That seems a functionality from Rails 4.

Example from docs:

date_field("user", "born_on")
# => <input id="user_born_on" name="user[born_on]" type="date" />

Upvotes: 17

Related Questions