Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActiveRecord::StatementInvalid(运行时错误:连接不能在分叉进程中重用)_Ruby On Rails_Ruby_Oracle_Cancan - Fatal编程技术网

Ruby on rails ActiveRecord::StatementInvalid(运行时错误:连接不能在分叉进程中重用)

Ruby on rails ActiveRecord::StatementInvalid(运行时错误:连接不能在分叉进程中重用),ruby-on-rails,ruby,oracle,cancan,Ruby On Rails,Ruby,Oracle,Cancan,您好,我正在使用CANCAN Gem作为用户角色和 database ->oracle oracle adaptor - > oracle_enhanced_adaptor 1.4.1 ruby 1.9.3 rails 3.2.16 web server -> unicorn 当我在一段时间后(2或3分钟)刷新broser时,它会给我们提供ActiveRecord::StatementInvalid(运行时错误:连接无法在分叉进程中重用)。: 任何人都可以帮助我,您需要将此添

您好,我正在使用
CANCAN Gem
作为用户角色和

database ->oracle
oracle adaptor - > oracle_enhanced_adaptor 1.4.1
ruby 1.9.3
rails 3.2.16
web server -> unicorn
当我在一段时间后(2或3分钟)刷新broser时,它会给我们提供
ActiveRecord::StatementInvalid(运行时错误:连接无法在分叉进程中重用)。


任何人都可以帮助我,您需要将此添加到您的unicorn.rb文件中

#config/unicorn.rb
after_fork do |server, worker|
  defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
end

您可以使用命令
unicorn-c config/unicorn.rb运行服务器来使用配置。

我从谷歌社区找到了答案

dbconfig = ActiveRecord::Base.remove_connection
child_pid = fork do
# establish new db connection for forked child
  ActiveRecord::Base.establish_connection(dbconfig)
   # do stuff...
end
# re-establish db connection
ActiveRecord::Base.establish_connection(dbconfig)
# detach the process so we don't wait for it
Process.detach(child_pid)

environment.rb
文件中,它像一个符咒一样工作

这是在哪个Web服务器下运行的?(独角兽、webrick、乘客、彪马…)根据您的web服务器的不同,您可能需要在forking.unicorn web服务器之后重新连接我正在使用我在config文件夹中添加了一个新文件unicorn.rb,并在运行服务器后粘贴代码,如rails s unicorn-c config/unicorn.rb它为我们提供了
':未定义的方法