Heroku路由错误:ActionController :: RoutingError

时间:2013-03-17 20:40:29

标签: ruby-on-rails heroku

我的routes.rb

中有以下内容
  constraints subdomain: 'api' do
    namespace :api, path: nil, defaults: {format: 'json'} do
      namespace :v1 do
        resources :cities, only: [:index] do
          resources :areas, only: [:index]
        end
      end
    end
  end

已在本地测试并且可以正常工作,但是当我部署到heroku时,我收到以下错误:

2013-03-17T20:35:04+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/v1/cities.json"):
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/rack/logger.rb:32:in `call_app'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/rack/logger.rb:16:in `block in call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/tagged_logging.rb:22:in `tagged'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/rack/logger.rb:16:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/request_id.rb:22:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/static.rb:62:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/engine.rb:479:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:223:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.5.8.72/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:18:in `call'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:552:in `process_client'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:632:in `worker_loop'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.5.8.72/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:18:in `block (4 levels) in <top (required)>'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:142:in `start'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/unicorn-4.6.2/bin/unicorn_rails:209:in `<top (required)>'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/bin/unicorn_rails:23:in `load'
2013-03-17T20:35:04+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/bin/unicorn_rails:23:in `<main>'

1 个答案:

答案 0 :(得分:0)

Heroku上的主机是否设置为api.yourdomain,或者您使用的是subdomain.herokuapp.com主机?

如果子域名不是api,则此行会导致您的路由失败:

constraints subdomain: 'api' do