Rails/Devise - NoMethodError(#的未定义方法 new_with_session')
我遇到了一个非常奇怪的问题,在我的生产环境(FreeBSD/Apache/Passenger/MySQL)上进行测试/错误修复期间出乎意料地出现了:
$ tail log/production.log
Started GET "/users/sign_up" for 192.168.5.7 at 2011-08-06 21:37:53 +0400
Processing by Devise::RegistrationsController#new as
SQL (1.5ms) SHOW TABLES
Completed in 15ms
NoMethodError (undefined method `new_with_session' for #<Class:0x2b2a4e34>):
app/controllers/registrations_controller.rb:71:in `build_resource'
app/controllers/registrations_controller.rb:8:in `new'
用户管理是用 Devise gem 组织的。登录页面正常,注册页面抛出此错误。
一切都很顺利,直到我更改了数据库中的一个字段(与 Devise 无关)(更改了类型 int -> bigint),并上传了 db/schema.rb 和 db/migrations/20110412205837_rename_files.rb。然后我用 重置数据库
$ rake db:setup RAILS_ENV='production'
,用 重新启动应用程序
$ touch tmp/restart.txt
,尝试注册为新用户 - 然后在日志文件中看到那个令人不满意的错误页面和 NoMethodError 报告。我没有更改 models/user.rb 文件中的 devise 部分(好吧,我做了,但之后我也重新启动了应用程序,一切都很好)。
这是我的 models/user.rb devise 部分:
devise :database_authenticatable, :registerable
我确信这是一个悲惨的问题,可能是其他错误,一个非常小的令人讨厌的错误,但我无法想象它会是什么......我已经找了两天了,不知道还能去哪里找。请人们帮忙!
我已经尝试过以下操作:
- 返回到以前版本的db/schema.rb,并重置DB;
- 整个rails应用程序降级到之前的版本;
- 将 app/controllers/registrations_controller.rb 移动到 app/controllers/devise 和 app/controllers/registrations 目录;
- 将设计宝石从 1.1.7 降级至 1.1.2;
- 重新启动了 Passenger、Apache 和整个 FreeBSD;
- 查看 /var/log/httpd.log 和 /var/log/httpd_error.log 文件;
- 重新创建数据库;
- 检查并重新创建 MySQL 用户和授权;
- 捆绑包更新;
没有任何帮助...
我还能做什么?为什么会出现这个问题呢?
非常感谢您提前提出的任何意见!
I've got a very strange issue, which arose quite unexpectedly during testing/bugfixing on my production environment (FreeBSD/Apache/Passenger/MySQL):
$ tail log/production.log
Started GET "/users/sign_up" for 192.168.5.7 at 2011-08-06 21:37:53 +0400
Processing by Devise::RegistrationsController#new as
SQL (1.5ms) SHOW TABLES
Completed in 15ms
NoMethodError (undefined method `new_with_session' for #<Class:0x2b2a4e34>):
app/controllers/registrations_controller.rb:71:in `build_resource'
app/controllers/registrations_controller.rb:8:in `new'
User management is organized with Devise gem. Sign in page is OK, Sign up page throws this error.
Everything went very well till I changed one of the fields (not related to Devise) in the database (changed type int -> bigint), and uploaded db/schema.rb and db/migrations/20110412205837_rename_files.rb. Then I reset the database with
$ rake db:setup RAILS_ENV='production'
, restarted the app with
$ touch tmp/restart.txt
, tried to sign up as a new user - and then saw that unhappy error page and the NoMethodError report in log file. I didn't change the devise section in models/user.rb file (OK, I did, but I also restarted the app after that and all was fine).
Here is my models/user.rb devise section:
devise :database_authenticatable, :registerable
I am sure that this is a miserable issue, maybe a mistype of something else, a very little nasty bug, but I can't imagine what it can be... I've been looking for it for two days and I don't know where else to look. Please people help!
I've already tried the following:
- Returned to the previous version of db/schema.rb, and reset the DB;
- Downgraded to the previous version of the whole rails app;
- Moved app/controllers/registrations_controller.rb to app/controllers/devise
and app/controllers/registrations directories; - Downgraded Devise gem from 1.1.7 to 1.1.2;
- Restarted Passenger, Apache, and the whole FreeBSD;
- looked in the /var/log/httpd.log and /var/log/httpd_error.log files;
- recreated the database;
- checked and recreated MySQL users and grants;
- Bundle update;
Nothing helps...
What else can I do? Why did this problem appear?
Thanks VERY MUCH to any input in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于经历这种痛苦的其他人来说,您可能和我一样愚蠢,忘记了 include:
在您的模型中。
For anyone else experiencing this pain, there is a chance you were as silly as me and forgot include:
in your model.
我将整个应用程序目录的所有者更改为www
(虽然当时没有帮助)
然后,更新了之前降级的(在寻找bug期间)设计到最新的1.4.2版本,
然后一切都有帮助。我认为(虽然我不明白为什么)文件的所有者应该与 httpd 进程的所有者是同一所有者(使用
$ ps aux | grep httpd
检查)。希望它能帮助某人
I changed the owner of the whole app directory to www
(didn't help at that moment though)
Then, updated previously downgraded (during the bug hunt) Devise to the latest 1.4.2 version with
Then it all helped. I think (though I don't understand why) that the owner of the files should be the same owner as the owner of httpd process (check with
$ ps aux | grep httpd
).Hopefuly it will help someone