有意思的。当RAILS_ENV是production时,ObjectSpace不包含trace_object_allocations_start方法(和相关方法)。有没有办法改变这一点?
[dhaskin@six plume (master *$%=)]$ rails c
Loading development environment (Rails 4.2.6)
[1] pry(main)> ObjectSpace.trace_object_allocations_start
=> nil
[2] pry(main)>
[dhaskin@six plume (master *$%=)]$ RAILS_ENV=production rails c
W, [2016-06-05T09:46:20.872062 #12364] WARN -- : ** [Honeybadger] Unable to start Honeybadger -- api_key is missing or invalid. level=2 pid=12364
Loading production environment (Rails 4.2.6)
2.3.1 :001 > ObjectSpace.trace_object_allocations_start
NoMethodError: undefined method `trace_object_allocations_start' for ObjectSpace:Module
from (irb):1
from /Users/dhaskin/.rvm/gems/ruby-2.3.1@plume/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
from /Users/dhaskin/.rvm/gems/ruby-2.3.1@plume/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
from /Users/dhaskin/.rvm/gems/ruby-2.3.1@plume/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/dhaskin/.rvm/gems/ruby-2.3.1@plume/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/dhaskin/.rvm/gems/ruby-2.3.1@plume/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
2.3.1 :002 >(请注意,在运行服务器时也会发生这种情况,这只是一种简单的演示方法。)
发布于 2016-06-06 08:50:53
事实证明这些ObjectSpace扩展是必需的,所以如果我添加
require 'objspace'它在生产中的工作与预期的一样。我最好的猜测是development中加载的一些gem正在为我做这个require,这就是为什么我不需要显式地要求它。
https://stackoverflow.com/questions/37644428
复制相似问题