I’ve using a calendar gem that uses start_time
for the date (YYYY-MM-DD).
For example purposes I’ve got Meeting
, which has start_time
string and postponed
boolean attributes.
@meeting.start_time
must be at least one day in the future (the day after today), but you can’t set a new start_time
(Meeting Date) if @meeting.postponed
, only if @meeting.postponed == false
I would like validations so when updating the Meeting (if @meeting
was previously postponed), I want to unselect the @meeting.postponed
checkbox and submit a new @meeting.start_date
in the form, and have it pass in the same submission.
if in the controller, something like:
@meeting.attributes = meeting_params
if @meeting.start_time != ""
if @meeting.start_time_changed?
if @meeting.posteponed
@error = "Can't change the Meeting Date if the Meeting is still postponed."
else
if @meeting.start_time.to_date <= Date.today
@error = "Meeting must be at least one day in the future."
end
end
end
else
@error = "Meeting Date cannot be blank."
end
How can I do this with validations?