#NoMethodError (undefined method `reject' for 0:Integer

1.1k Views Asked by At

I am using ruby 3.0 and rails 7.0.2 for my application. when i try to run console or generate controller or migration it gives me this error:

NoMethodError (undefined method `reject' for 0:Integer Did you mean? rect):

if existing_problem_sets.present? 
  existing_problem_sets.each do |problem_set| 
    problem_set.update!(
      sat_question_id: problem_set.sat_question_id.reject{|x| x==self.id.to_s}, 
      sat_position: problem_set.sat_position.reject{|x| x[:sat_question_id] == self.id.to_s}) 
  end #do
end #if
1

There are 1 best solutions below

0
radarbob On

sat_question_id: problem_set.sat_question_id.reject{|x| x==self.id.to_s}

@mechnicov comment may be the key.

  • The error message tells you that the method reject does not exist in the Integer class (it is "undefined")
  • Immediately you should be telling yourself "I need to lookup the Integer class in the Ruby docs."
  • Where is reject being called? Right there! so sat_question_id might be/must be an integer.
  • What are the current values of the object(s) in that code? If they are correct then maybe the code is wrong. What object(s)/Classes do I have that have a reject method?

Based on this snippit - x==self.id.to_s - I am going to GUESS you meant to code something like this:

sat_question_id: problem_set.reject{|x| x.sat_question_id.to_s == self.id.to_s}, 

Nobody's answer will be better than a guess without seeing your data class(es) declarations and some actual instantiated objects. The actual object that caused the accident.