Hellboy
Hellboy

Reputation: 1239

Partial date in Rails

I have a date type column in my table which is taken input from a form using f.input. But, I want only the month and year to be taken from the form. Is there any way that I can hide the day dropdown or is there any other data type which can take care of this?

Upvotes: 0

Views: 246

Answers (1)

Vucko
Vucko

Reputation: 20834

From the documentation:

:discard_day - Set to true if you don’t want to show a day select. This includes the day as a hidden field instead of showing a select field. Also note that this implicitly sets the day to be the first of the given month in order to not create invalid dates like 31 February.

Example from the docs:

date_select("article", "written_on", start_year: 1995, use_month_numbers: true, discard_day: true, include_blank: true)

Upvotes: 3

Related Questions