TypeError:在使用Rails 3.2项目中的模型对象时,Proc的undeator为undefined

时间:2012-03-16 10:02:56

标签: ruby-on-rails

当我使用继承了ActiveRecord :: Base的User的类型为Staffer的对象时,我得到错误“TypeError:allocator undefined for Proc”。

我不确定是什么导致它开始发生的,不幸的是,跟踪提交的内容并不容易。由于系统运行正常,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 >

1 个答案:

答案 0 :(得分:8)

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

如果是这样,我认为它与序列化数据有关,而与代码无关。检查你的序列化数据中是否有序列化的Proc对象......那应该是它无法加载的原因,导致某些程序无法序列化!?

请参阅this论坛帖子。