NoMethodError:#< NoMethodError: ...> 的未定义方法“结果”
堆栈跟踪指的是这个地方:
def current_income
return @current_income if defined? @current_income
if session[:income_id] && session[:income_id] != nil
@current_income ||= Income.find session[:income_id] # Line 13 - error place
else
create_current_income # Creates new income method
end
return @current_income
end
此错误仅在 heroku 上的生产模型中。我的配置:
- Ruby 2.0.0 + Rails 3.2.13
- 独角兽服务器 + Postgresql 9.3
一开始似乎线程和 Postgresql 连接存在问题,但我已经为 ActiveRecord 做了所有分叉工作:
# config/unicorn.rb
worker_processes Integer(ENV['WEB_CONCURRENCY'] || 3)
timeout Integer(ENV['WEB_TIMEOUT'] || 15)
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
有人遇到过类似的问题可以帮我给小费吗?