gpt4 book ai didi

ruby-on-rails - TypeError:在Rails 3.2项目中使用模型对象时,Proc的分配器未定义

转载 作者:行者123 更新时间:2023-12-02 07:07:15 24 4
gpt4 key购买 nike

当我处理Staffer类型的对象时,该对象继承了User,后者又继承了ActiveRecord::Base,因此出现错误“TypeError:Proc分配器 undefined ”。

我不确定是什么原因导致它开始发生的,不幸的是,要跟踪所做的提交并不容易。由于系统运行正常,因此user.rb不变,而staffer.rb仅更改一行以删除未使用的常量。

我首先在运行rake任务时注意到该错误,并且该错误是从执行此操作的行生成的:

attributes.slice("id", "email", "state")

进一步的调查表明,这也触发了错误:
puts attributes

这是回溯:
rake aborted!
allocator undefined for Proc
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:227:in `allocate'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:227:in `revive'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:183:in `visit_Psych_Nodes_Mapping'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/delayed_job-3.0.1/lib/delayed/psych_ext.rb:119:in `visit_Psych_Nodes_Mapping_with_class'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/visitor.rb:7:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:16:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `block in revive'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `map'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `revive'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:183:in `visit_Psych_Nodes_Mapping'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/delayed_job-3.0.1/lib/delayed/psych_ext.rb:119:in `visit_Psych_Nodes_Mapping_with_class'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/visitor.rb:7:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:16:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:116:in `block in visit_Psych_Nodes_Sequence'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:116:in `each'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:116:in `visit_Psych_Nodes_Sequence'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/visitor.rb:8:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:16:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `block in revive'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `map'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `revive'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:183:in `visit_Psych_Nodes_Mapping'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/delayed_job-3.0.1/lib/delayed/psych_ext.rb:119:in `visit_Psych_Nodes_Mapping_with_class'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/visitor.rb:7:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:16:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `block in revive'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `map'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `revive'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:183:in `visit_Psych_Nodes_Mapping'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/delayed_job-3.0.1/lib/delayed/psych_ext.rb:119:in `visit_Psych_Nodes_Mapping_with_class'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/visitor.rb:7:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:16:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:191:in `block in visit_Psych_Nodes_Mapping'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:190:in `each'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:190:in `each_slice'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:190:in `visit_Psych_Nodes_Mapping'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/delayed_job-3.0.1/lib/delayed/psych_ext.rb:119:in `visit_Psych_Nodes_Mapping_with_class'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/visitor.rb:7:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:16:in `accept'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/nodes/node.rb:25:in `to_ruby'
/Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:107:in `load'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/coders/yaml_column.rb:25:in `load'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/serialization.rb:24:in `unserialize'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/serialization.rb:15:in `unserialized_value'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/read.rb:82:in `__temp__'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/read.rb:46:in `type_cast_attribute'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/read.rb:126:in `read_attribute'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods.rb:183:in `block in attributes'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods.rb:183:in `each'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods.rb:183:in `map'
/Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods.rb:183:in `attributes'
/Users/pupeno/Documents/watu/app/models/staffer.rb:151:in `index'

为了弄清楚发生了什么,我打开了一个rails控制台,并得到了第一个职员,遇到了同样的错误:
1.9.2-p290 :019 > s = Staffer.first
Staffer Load (3.8ms) SELECT "users".* FROM "users" WHERE "users"."type" IN ('Staffer') LIMIT 1
TypeError: allocator undefined for Proc
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:227:in `allocate'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:227:in `revive'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:183:in `visit_Psych_Nodes_Mapping'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/delayed_job-3.0.1/lib/delayed/psych_ext.rb:119:in `visit_Psych_Nodes_Mapping_with_class'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/visitor.rb:7:in `accept'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:16:in `accept'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `block in revive'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `map'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:228:in `revive'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:183:in `visit_Psych_Nodes_Mapping'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/delayed_job-3.0.1/lib/delayed/psych_ext.rb:119:in `visit_Psych_Nodes_Mapping_with_class'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/visitor.rb:7:in `accept'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:16:in `accept'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:116:in `block in visit_Psych_Nodes_Sequence'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:116:in `each'
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:116:in `visit_Psych_Nodes_Sequence'
... 24 levels...
from /Users/pupeno/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/psych.rb:107:in `load'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/coders/yaml_column.rb:25:in `load'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/serialization.rb:24:in `unserialize'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/serialization.rb:15:in `unserialized_value'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/read.rb:82:in `__temp__'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/read.rb:46:in `type_cast_attribute'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods/read.rb:126:in `read_attribute'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/attribute_methods.rb:200:in `attribute_for_inspect'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/base.rb:640:in `block in inspect'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/base.rb:638:in `collect'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/activerecord-3.2.2/lib/active_record/base.rb:638:in `inspect'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
from /Users/pupeno/.rvm/gems/ruby-1.9.2-p290@watu/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.2-p290 :020 >

最佳答案

您的人员/用户字段之一中是否有任何yaml序列化数据?

如果是这样,我认为这与序列化数据有关,与您的代码无关。检查序列化数据中是否有一个序列化的Proc对象左右……这应该是无法加载它的原因,导致Procs无法序列化!

请参阅this论坛帖子。

关于ruby-on-rails - TypeError:在Rails 3.2项目中使用模型对象时,Proc的分配器未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9735188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com