The date_select
helper makes use of what Rails calls multi parameter attributes. That is, the value of the release_date
attribute is split across the 3 dropdowns for day, month, year which are created by the date_select
helper. date_select
names the 3 dropdowns following a convention such that in your controller you can do:
@game = Game.new(params[:game])
and the release_date
attribute on the new game will be populated with the date selected.
or
@game.update_attributes(params[:game])
to update an existing record.
If you inspect params or look in the log file you will see the 3 individual components:
params["game"]["release_date(1i)"] # the year
params["game"]["release_date(2i)"] # the month
params["game"]["release_date(3i)"] # the day
Whilst you could access these individual elements directly it doesn't seem like a good idea. The date_select
helper is really designed to be used in combination with the attributes=
setter of ActiveRecord which is used when creating a new object or updating attributes.