About validate

Asked 2 years ago, Updated 2 years ago, 46 views

Prerequisites/What you want to achieve

I'd like to implement the feature so that I can't post if I set a date before yesterday when I post.

We are creating a posting application that opens after the date specified in rails.
The following error message occurred while implementing the above features:

Problems/Error Messages you are experiencing

ArgumentError in ItemsController#create

comparison of time with nil failed

Source Codes Affected

Ruby

validate:judge_future

private

def judge_future
 return unless open_day
  if(Time.now+1.day)>=open_day#If it's more past today, error
   US>Errors.add(:open_day, ' should be set to tomorrow or later.')
  end
end

If you know how to deal with it, please leave a comment.

ruby-on-rails ruby

2022-09-30 19:57

1 Answers

The comparison of time with nil failed error is

 if(Time.now+1.day)>=open_day

It is thought to have occurred in the determination of the conditions in .This is because this is the only part of the question code that is being compared.

The reason for the error is 'open_day is nil' because the direct translation of the message is 'Time and nil comparison failed'.

There is no code in the question that is substituted for open_day substitute.
·The part where some value is substituted for open_day is missing
·The value was supposed to be substituted for open_day where it was not the code of the question, but it is not working.
It is possible that

I think the date specified in rails in the question is open_day, but no one will know what to do because the code for the part that specifies the date is not shown.


2022-09-30 19:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.