You could fiddle with the param in the controller. Here is a mock-up:
now = Time.now
param_date = params[:project_time][:date]
params[:project_time][:date] = case
when /^\d$/ then Time.mktime(now.year, now.month, param_date)
…
else param_date
end
I found another solution, which I think is the way to go, as the date
is corrected just as it is added to the model.
So the model always holds correct data.
I overwrite the date= method in my model
class ProjectTime < ActiveRecord::Base
…
def date=(value)
check value and do the filtering
value = …
set attribute im my model class
self[:date] = value
end
end
Alex
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.