1

我的 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>'
4

1 回答 1

0

您在 Heroku 上的主机设置为api.yourdomain还是正在使用subdomain.herokuapp.com主机?

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

constraints subdomain: 'api' do
于 2013-03-17T21:02:34.450 回答