Rails Grape 在 Nginx + Unicorn + rbenv 无法加载

liuhui998 · 2012年04月26日 · 最后由 liuhui998 回复于 2013年06月18日 · 4628 次阅读

最近有一个项目,使用了 grape 来进行 api 的处理 在本地是使用 WEBrick 在 development 下一切正常

class API < Grape::API prefix "api" version 'v1'

.......... end

但是布署到了服务器端后,查看 unicorn.rb 提示:

uninitialized constant Grape (NameError) /funny1/apps/menu/releases/20120426060007/lib/api/api.rb:7:in `'

详细 log:

E, [2012-04-26T15:50:19.057859 #20422] ERROR -- : reaped #<Process::Status: pid 28044 exit 1> worker=1
I, [2012-04-26T15:50:19.058028 #20422]  INFO -- : worker=1 spawning...
I, [2012-04-26T15:50:19.065295 #28050]  INFO -- : worker=1 spawned pid=28050
I, [2012-04-26T15:50:19.065683 #28050]  INFO -- : Refreshing Gem list
E, [2012-04-26T15:50:19.162059 #28047] ERROR -- : uninitialized constant Grape (NameError)
/funny1/apps/menu/releases/20120426060007/lib/api/api.rb:7:in `<top (required)>'
/funny1/apps/menu/releases/20120426060007/config/routes.rb:23:in `block in <top (required)>'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:258:in `instance_exec'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:258:in `eval_block'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/actionpack-3.1.3/lib/action_dispatch/routing/route_set.rb:235:in `draw'
/funny1/apps/menu/releases/20120426060007/config/routes.rb:1:in `<top (required)>'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/application/routes_reloader.rb:29:in `block in load_paths'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/application/routes_reloader.rb:29:in `each'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/application/routes_reloader.rb:29:in `load_paths'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/application/routes_reloader.rb:13:in `reload!'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/application.rb:87:in `reload_routes!'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/rails.rb:14:in `block in <class:Engine>'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:34:in `call'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:42:in `each'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.3/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/application/finisher.rb:50:in `block in <module:Finisher>'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `instance_exec'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `run'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:55:in `block in run_initializers'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `each'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `run_initializers'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/application.rb:96:in `initialize!'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/railties-3.1.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/funny1/apps/menu/releases/20120426060007/config/environment.rb:5:in `<top (required)>'
config.ru:4:in `require'
config.ru:4:in `block in <main>'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `instance_eval'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/rack-1.3.6/lib/rack/builder.rb:51:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/lib/unicorn.rb:44:in `eval'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/lib/unicorn.rb:44:in `block in builder'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/lib/unicorn/http_server.rb:695:in `call'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/lib/unicorn/http_server.rb:695:in `build_app!'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/lib/unicorn/http_server.rb:568:in `init_worker_process'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/lib/unicorn/http_server.rb:588:in `worker_loop'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/lib/unicorn/http_server.rb:487:in `spawn_missing_workers'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/lib/unicorn/http_server.rb:498:in `maintain_worker_count'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/lib/unicorn/http_server.rb:272:in `join'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.0/bin/unicorn:121:in `<top (required)>'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/bin/unicorn:19:in `load'
/funny1/apps/menu/shared/bundle/ruby/1.9.1/bin/unicorn:19:in `<main>'
E, [2012-04-26T15:50:19.170926 #20422] ERROR -- : reaped #<Process::Status: pid 28047 exit 1> worker=0
I, [2012-04-26T15:50:19.171148 #20422]  INFO -- : worker=0 spawning...
I, [2012-04-26T15:50:19.179755 #28053]  INFO -- : worker=0 spawned pid=28053
I, [2012-04-26T15:50:19.180256 #28053]  INFO -- : Refreshing Gem list

grape 在 Gemfile 里是肯定有的

RAILS_ENV=production bundle exec rails c require 'grape'

也是没有异常的

如果实在不行,只有用 rails 手写 api 了

刚才我抱着试试看的想法,把服务器重启了 问题解决了:)

@liuhui998 我也遇到同样的问题了,请问你是怎么解决的呢

@tomwey 前面说了,只是重启一下服务器就好了

需要 登录 后方可回复, 如果你还没有账号请 注册新账号