I'm really struggling with what should be a fairly simple task
Before I had select_time and select_date and to separate the date and time but I can't figure out how to get it to a readable format to compare to Time.now
.
I just want 2 validations, cannot start an event in the past, and cannot end an event before the start
In my form
<%= f.label :date_start %>
<%= f.datetime_select :date_start %>
In my event model
validate :start_date_cannot_be_in_the_past
def start_date_cannot_be_in_the_past
date = Time.new(date_start(1i).to_i, date_start(2i).to_i, date_start(3i).to_i, date_start(4i).to_i, date_start(5i).to_i)
if date < Time.now
errors.add(:date_start, "has already passed")
end
end
Date + time selectors all break down values like this
"date_start(1i)"=>"2014",
"date_start(2i)"=>"11",
"date_start(3i)"=>"8",
"date_start(4i)"=>"04",
"date_start(5i)"=>"13"},