Setting the value: as many of these answers indicate, will overwrite the value that is passed for any record being edited. This is not a problem if the form is intended only for new records, but a mistake if you want to edit records in the form. One way to do this is to explicitly capture an existing object, as Michael suggests.
The solution I'm currently using is in the controller, which sets the value today when it creates a new record. Assuming your model is Person, and the value you want to use by default is start_date:
def new @person = Person.new(start_date: Date.current) end
Then you can simply use the value in the form without any additional fuss.
f.date_field :start_date
Jemima
source share