2014-12-24 1 views
0

내 레일 앱에 포도 (0.9.0) API를 추가하려고합니다. 로컬 서버에서 완벽하게 작동하지만, 카피 스트라 노를 사용하여 서버로 푸시하려고하면 프리 컴파일 : 자산 단계에서 실패합니다. 설정/application.rb에레일에서 초기화되지 않은 상수 4 배포에서만 포도가 발생 함

NameError: uninitialized constant API 
/home/deploy/pl2/releases/20141224200546/config/routes.rb:4:in `block in <top (required)>' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/routing/route_set.rb:337:in `eval_block' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.8/lib/action_dispatch/routing/route_set.rb:315:in `draw' 
/home/deploy/pl2/releases/20141224200546/config/routes.rb:1:in `<top (required)>' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application/routes_reloader.rb:40:in `block in load_paths' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application/routes_reloader.rb:40:in `each' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application/routes_reloader.rb:40:in `load_paths' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application/routes_reloader.rb:16:in `reload!' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application/routes_reloader.rb:26:in `block in updater' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/file_update_checker.rb:75:in `call' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/file_update_checker.rb:75:in `execute' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application/routes_reloader.rb:27:in `updater' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `instance_exec' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `run' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:55:in `block in run_initializers' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/initializable.rb:54:in `run_initializers' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:300:in `initialize!' 
/home/deploy/pl2/releases/20141224200546/config/environment.rb:5:in `<top (required)>' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:276:in `require_environment!' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/application.rb:389:in `block in run_tasks_blocks' 
/home/deploy/pl2/shared/bundle/ruby/2.1.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define' 
Tasks: TOP => environment 
(See full trace by running task with --trace) 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/command.rb:97:in `exit_status=' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:153:in `block (5 levels) in _execute' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `do_request' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:561:in `channel_request' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:269:in `wait' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:175:in `block (3 levels) in _execute' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `call' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:221:in `preprocess' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:205:in `process' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `block in loop' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/net-ssh-2.9.1/lib/net/ssh/connection/session.rb:169:in `loop' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:177:in `block (2 levels) in _execute' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:191:in `with_ssh' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:136:in `block in _execute' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:133:in `tap' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:133:in `_execute' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:66:in `execute' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/capistrano-rails-1.1.2/lib/capistrano/tasks/assets.rake:59:in `block (6 levels) in <top (required)>' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/abstract.rb:85:in `with' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/capistrano-rails-1.1.2/lib/capistrano/tasks/assets.rake:58:in `block (5 levels) in <top (required)>' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/abstract.rb:77:in `within' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/capistrano-rails-1.1.2/lib/capistrano/tasks/assets.rake:57:in `block (4 levels) in <top (required)>' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/backends/netssh.rb:54:in `run' 
/Users/briankeane/.rvm/gems/ruby-2.1.2/gems/sshkit-1.6.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute' 
Tasks: TOP => deploy:assets:precompile 

:

Rails.application.routes.draw do 
    mount API::Root => "/" # this is throwing the error (routes.rb:4) 
    # ... other routes 
end 

응용 프로그램/API/API/루트 routes.rb 설정 /에서

module Web 
    class Application < Rails::Application 
    config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb') 
    config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')] 
    # ... etc 
    end 
end 

여기 카피 스트라 노에서 스택 추적입니다. rb :

module API 
    class Root < Grape::API 
    prefix "api" 

    mount API::V1::Root 
    end 
end 

app/api/API/V1/root.rb

module API 
    module V1 
    class Root < Grape::API 
     version "v1" 
     format :json 
     #error_format :json 

     # load the rest of the API 
     mount API::V1::Songs 
    end 
    end 
end 

그리고 마지막으로, 응용 프로그램/API/API/V1/songs.rb

module API 
    module V1 
    class Songs < Grape::API 
     # /api/users 
     version "v1" 
     format :json 

     resource :songs do 
     desc "get a song" 
     params do 
      requires :id, type: Integer, desc: "song_id" 
     end 
     route_param :id do 
      get do 
      { title: 'test' } 
      end 
     end 
     end 
    end 
    end 
end 

모든 것은 내가 RAILS_ENV = 생산을 설정할 경우에도 내 로컬 컴퓨터에서 잘 작동하는 것 같다. 거기에 비슷한 질문 here,하지만 그것은 로컬로 작동하기 때문에 그게 문제라고 생각하지 않습니다. 감사! 난 아직 여기에 더 나은 솔루션을 찾고 있지만있어

답변

1

같은 문제가 있습니다. 나는 autoload_pathspaths 구성이 중요하다고 생각한다.

module Web 
    class Application < Rails::Application 
    config.paths.add File.join('app', 'api'), glob: File.join('**', '**', '*.rb') 
    config.autoload_paths += Dir[Rails.root.join('app', 'api', '**', '**', '*')] 
    # ... etc 
    end 
end 

모든 단지 일 : I가 설정/application.rb을 변경할 때 너무

app 
└── api 
   └── API 
    ├── V1 
    │   └── songs.rb 
    └── root.rb 

:

이 파일 구조입니다.

1

내가 그동안했던 해키 것은 그것을 얻기 위해 단지의 경우 사람에 실행하면 같은 문제가 발생하는 것입니다 및 빠른 수정이 필요 : 상기

다음
require_relative '../app/api/API/root.rb' 

AP에서/API/API/V1/root.rb : 내 routes.rb 파일의 맨 위에 다시

require_relative 'auth.rb' 
require_relative 'songs.rb' 
require_relative 'users.rb' 

-이 솔루션에 대한 흥분하지 그래서 추가 도움이 많이있다 고맙습니다.

+0

같은 문제. 우리가 .. 어딘가에 뭔가 빠져있는 것처럼 보입니다. – Mingsheng

관련 문제