#nomethoderror(未定义的方法'拒绝' for 0:integer

发布于 2025-01-30 01:43:54 字数 457 浏览 3 评论 0 原文

我正在使用Ruby 3.0和Rails 7.0.2用于我的应用。当我尝试运行控制台或生成控制器或迁移时,它给了我这个错误:

nomethoderror(未定义的方法“拒绝” 0:整数您的意思是?ect):

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§普罗旺斯的薰衣草 2025-02-06 01:43:54

SAT_QUESTION_ID:QUALICE_SET.SAT_QUESTION_ID.REXPERT {| X | x == self.id.to_s}

  • 错误消息告诉您,整数类中的方法拒绝不存在(即“未定义”)
  • ,您应该告诉自己“我需要在Ruby Docs中查找整数类。”
  • <代码>拒绝被调用在哪里?就在那儿!因此, sat_question_id 可能是/必须是整数。
  • 该代码中对象的当前值是多少?如果它们是正确的,那么代码可能是错误的。我有哪个对象/类有一个 recood 方法?

基于此snippit- x == self.id.to_s - 我要猜测您的意思是要编码这样的内容:

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

没有人的答案会比猜测更好,而无需看到您的数据类(ES)(ES)声明和一些实际实例化对象。导致事故的实际物体。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文