Rails4でGrapeを使ってAPIを作成してHerokuに上げたら本番だけエラーが発生してしまった。
Ruby on Rails4でGrapeを使ってAPIを作ってHeroku上にあげたのですが、本番環境だけ以下のログが出てしまって、Application Errorでサイトが落ちてしまいます。開発環境ではしっかりと動くのですが。。
ログをみると何故か/app/api
2016-04-10T08:45:07.470872+00:00 app[worker.1]: uninitialized constant API::Root::V1 2016-04-10T08:45:07.470893+00:00 app[worker.1]: /app/app/api/api/root.rb:8:in `' 2016-04-10T08:45:07.470894+00:00 app[worker.1]: /app/app/api/api/root.rb:2:in `' 2016-04-10T08:45:07.470895+00:00 app[worker.1]: /app/app/api/api/root.rb:1:in `' 2016-04-10T08:45:07.470895+00:00 app[worker.1]: /app/config/routes.rb:55:in `block in ' 2016-04-10T08:45:07.470897+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:434:in `instance_exec' 2016-04-10T08:45:07.470898+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:412:in `draw' 2016-04-10T08:45:07.470897+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:434:in `eval_block' 2016-04-10T08:45:07.470899+00:00 app[worker.1]: /app/config/routes.rb:2:in `' 2016-04-10T08:45:07.470900+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:40:in `block in load_paths' 2016-04-10T08:45:07.470900+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:40:in `each' 2016-04-10T08:45:07.470902+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:16:in `reload!' 2016-04-10T08:45:07.470901+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application/routes_reloader.rb:40:in `load_paths' 2016-04-10T08:45:07.470903+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application.rb:170:in `reload_routes!' 2016-04-10T08:45:07.470903+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/devise-3.5.6/lib/devise/rails.rb:14:in `block in ' 2016-04-10T08:45:07.470904+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:36:in `call' 2016-04-10T08:45:07.470905+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook' 2016-04-10T08:45:07.470906+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks' 2016-04-10T08:45:07.470906+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:44:in `each' 2016-04-10T08:45:07.470909+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec' 2016-04-10T08:45:07.470910+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers' 2016-04-10T08:45:07.470912+00:00 app[worker.1]: /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each' 2016-04-10T08:45:07.470907+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks' 2016-04-10T08:45:07.470908+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application/finisher.rb:55:in `block in ' 2016-04-10T08:45:07.470909+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run' 2016-04-10T08:45:07.470916+00:00 app[worker.1]: /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each' 2016-04-10T08:45:07.470918+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers' 2016-04-10T08:45:07.470918+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!' 2016-04-10T08:45:07.470912+00:00 app[worker.1]: /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component' 2016-04-10T08:45:07.470919+00:00 app[worker.1]: /app/config/environment.rb:18:in `' 2016-04-10T08:45:07.470913+00:00 app[worker.1]: /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from' 2016-04-10T08:45:07.470920+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.1.0/lib/sidekiq/cli.rb:235:in `boot_system' 2016-04-10T08:45:07.470914+00:00 app[worker.1]: /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component' 2016-04-10T08:45:07.470921+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.1.0/lib/sidekiq/cli.rb:49:in `run' 2016-04-10T08:45:07.470915+00:00 app[worker.1]: /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `call' 2016-04-10T08:45:07.470922+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/bin/sidekiq:23:in `load' 2016-04-10T08:45:07.470914+00:00 app[worker.1]: /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each' 2016-04-10T08:45:07.470921+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/gems/sidekiq-4.1.0/bin/sidekiq:12:in `' 2016-04-10T08:45:07.470916+00:00 app[worker.1]: /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component' 2016-04-10T08:45:07.470923+00:00 app[worker.1]: /app/vendor/bundle/ruby/2.2.0/bin/sidekiq:23:in `' 2016-04-10T08:45:07.470917+00:00 app[worker.1]: /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
環境は
- Rails 4.2.5
- ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
routes.rb
mount API::Root => "/"
application.rb
config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb') config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')] config.middleware.use(Rack::Config) do |env| env['api.tilt.root'] = Rails.root.join 'app', 'views', 'api' end
フォルダの階層
- /app
- /api
- /api
- root.rb
- /V1
- root.rb
- articles.rb
- /api
- /api
/app/api/api/root.rb
module API class Root /app/api/api/V1/root.rb module API module V1 class Root :path mount V1::Articles end end end
/app/api/api/V1/articles.rb
module API module V1 class Articles
以上のようになっていて、localhostではちゃんとJSONが出力されるのですが、本番環境(Heroku)にプッシュすると上記のようなエラーが発生してしまって、その原因がわかりません。
エラーによると、/app/app/api/api/...と階層の最初に/appが何故か追加されていて、おそらくこのせいでRailsの命名規則?みたいなのに従ってないからダメ!みたいなことだと思うんですが、何故Herokuにあげたらこの/appという階層が追加されたかも理由がさっぱりです。
分かるかたいたら宜しくお願いします!!