I have a form field that posts a date range in the format "05/14/2013 - 05/22/2013". My model has two separate date fields, begin and end for the respective beginning and end dates from the form field. What is the best MVC way to approach getting the date range into the correct fields?
I've been trying to manually deconstruct the date range in the controller's create method, but it looks like the updated params aren't properly seen in the model before the record is created.
EDIT: The date range is coming in that format because I'm using Keith Wood's datepick, and it outputs the dates in a single input field.
What I've been trying to do currently is this (contract is the name of my model, and dates is the input date range:
beginDate = params[:dates].split("-")[0].strip()
endDate = params[:dates].split("-")[1].strip()
params.delete :dates
params[:contract][:begin] = Date.strptime(beginDate, '%m/%d/%Y')
params[:contract][:end] = Date.strptime(endDate, '%m/%d/%Y')
@contract = Contract.new(params[:contract])
... but these changes to params don't show up by the time the record is created and validated.
safe_updateor something where you do the extra work and try to update the model. - MrDanA