Cannot read property 'jqXHR' of undefined

This error showed for me when I was doing the following.
All done in a plugin.

I was adding a Validator to the Post class… the content of it does not matter but i will put it for the sake of the reply.

frozen_string_literal: true

class MainPostValidator < ActiveModel::Validator
def validate(record)
puts ‘TTTTT’
p record

raw = record.raw

unless raw.present?
  post.errors.add :base, 'This record is invalid'
end

end

private
def some_complex_logic
# …
end
end

Before running the server with the new changes, I had the website opened on editing a post, ready to check if the save changes triggers my validator.

I restarted the server but did not refresh the page! When I tapped save changes on the post. I saw that error. It disappeared once i refreshed the page, and maybe restarted the server instance also.

This was all done in local dev.

Hope it helps :slight_smile:

The validator was declared in a new file, and also the Post extra code to apply the validator was in a new file as well.

require_dependency 'post' Post.class_eval { include ActiveModel::Validations validates_with MainPostValidator }