Custom validation and presence validation

Code in my model is

validates :place_id, :title, :level, :start_at, :end_at, :presence =>
true
validate :event_takes_place_in_one_day, :event_is_not_in_past

def event_takes_place_in_one_day
self.start_at.day == self.end_at.day
end
def event_is_not_in_past
admissible_range =
DateTime.now.beginning_of_day…DateTime.now.end_of_month
admissible_range.cover?(self.start_at) &&
admissible_range.cover?(self.end_at)
end

I need to validate presence of start_at and end_at before my custom
validations, but this do not happen, here is the errors that I got

undefined method `to_datetime’ for nil:NilClass

app/models/meeting.rb:22:in cover?' app/models/meeting.rb:22:inevent_is_not_in_past’
app/controllers/meetings_controller.rb:18:in `create’

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs