今天在Rails production中登录时发现了500错误,提示uninitialized constant Digest::SHA1,于是上网搜资料,如下:
I'm trying to deploy a rails app to joyent/textdrive for the first time. All works well until I try to access Digest::SHA1.
I get the following:
NameError (uninitialized constant Digest::SHA1):
/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:263:in `load_missing_constant'
/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:452:in `const_missing'
/app/models/user.rb:48:in `encrypted_password'
/app/models/user.rb:20:in `authenticate'
/app/controllers/login_controller.rb:9:in `login'
/vendor/rails/actionpack/lib/action_controller/base.rb:1095:in `send'
etc.
While I didn't need to explicitly require digest/sha1 on my local box, I took this to mean that maybe on the production box I do.
I've tried placing the "require 'digest/sha1'" statement both at the top of my user.rb class and at the bottom of the environment.rb file, and have restarted both lighttpd and rails, but continue to get the same error.
I have run the rails:freeze:gems task and copied the entire vendor package to production.
Anyone have any ideas why I keep getting this exception or how to solve this?
Thanks!
-Drew
最后作者找到了解决方法:
Upon much experimentation I found that rather than just restarting the rails app via the
./script/process/reaper -a reload
command, I rather needed to physically kill the processes for lighttpd and rails and manually restart in order for the require statement to start working. I'm not sure if this was a caching issue or if a full killing and restart of all processes was actually needed to load the digest library.
Anyway, things are working happily now.
Thanks,
-Drew