我最近将 Rails 应用程序从 3.0.4 更新到 3.2.4,但遇到了一个奇怪的问题.我的应用程序中的每个数组似乎都被冻结了.例如,如果一个数组从数据库中获取一组文章,则该数组将在第一次调用该方法时实例化并且不会更改.如果数组中的一篇文章在数据库中被删除,它仍然会在数组中引用它.只有当我重新启动服务器时它才会改变.但是,当我调用 array.frozen 时?它返回假.当我部署到 heroku 时,我收到此错误:
I recently updated a rails app from 3.0.4 to 3.2.4 and I have a strange problem. It seems every array in my app has become frozen. For example if an array gets a set of articles from the database, that array will be instantiated at the first call of the method and will not change. If an article in the array is deleted in the database, it will still refer to it in the array. It only changes if I restart the server. However, when I call array.frozen? it returns false. And when I deploy to heroku I get this error:
!!处理请求时出现意外错误:无法修改冻结数组
!! Unexpected error while processing request: can't modify frozen array
关于可能导致这种情况的任何建议?我更新了另一个应用程序并没有遇到这个问题.
Any suggestions on what might be causing this? I updated another app and didn't run into this problem.
推荐答案好的,我搞定了.我运行 heroku run script/rails console 并且它给了我一个我还没有看到的新错误.原来在我的环境/生产.rb 文件中有一行随机代码,肯定是不小心复制和粘贴的.删除后,它清除了冻结阵列问题.在一些无关的 gem 问题之后,我能够让我的网站重新上线.所以我的建议是检查您的 production.rb 文件并运行 heroku 控制台.
Allright I got it working. I ran heroku run script/rails console and it gave me a new error that I hadn't seen yet. Turns out there was a random line of code in my environments/production.rb file that must've been copy and pasted accidentally or something. After removing it, it cleared up the frozen array problem. After some unrelated gem issues, I was able to get my site back online. So my advice is check your production.rb file and run the heroku console.
更多推荐
在 Rails 3.2.4 中冻结的数组
发布评论