我在我們的Rails 4.2.4應用程序中使用某些可安裝的引擎時遇到了一些問題。我們最近(我知道,我們很晚很難過)從Rails 3.2.23升級。我們的引擎路由在Rails 3.2.23中運行良好,但是當我嘗試訪問路由時(使用Paw或cURL),我得到一個RoutingError,沒有路由匹配。但是,當我查看rake routes
或http://localhost:3000/rails/info/routes
的輸出時,該路線實際上存在與正確的動詞和所有內容。從Rails 3升級後在Rails 4中可安裝的引擎路由錯誤
事情我看着:
- 路線不被別的東西下來的文件覆蓋,因爲我們所擁有的一切包在子域的限制。
- 我重新創建了可安裝引擎,使用最新版本的Rails並比較了差異。
此外,我正在使用versionist寶石。我不知道這是否是造成這種情況的原因,但似乎相關。
的Gemfile
gem 'api', path: 'engines/api'
配置/ routes.rb中
constraints subdomain: /^api/, format: :json do
mount Api::Engine, at: "/"
end
引擎/ API/LIB/API/engine.rb
module Api
class Engine < ::Rails::Engine
isolate_namespace Api
config.generators do |g|
g.template_engine :rabl
g.test_framework :rspec, view_specs: false
end
end
end
引擎/ API /配置/ routes.rb中
Api::Engine.routes.draw do
api_version(:module => "V1", :parameter => { :name => "version", :value => "1" }) do
resources :users
end
end
樣品捲曲請求
curl -X "GET" "http://api.myapp.dev:3000/users/new?api_key=foobar&version=1" \
-H "Accept: application/json" \
-H "Content-Type: application/json"
日誌/ development.log
ActionController::RoutingError (No route matches [GET] "https://stackoverflow.com/users/new"):
actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
rollbar (2.3.0) lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
railties (4.2.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
request_store (1.2.0) lib/request_store/middleware.rb:8:in `call'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
railties (4.2.4) lib/rails/engine.rb:518:in `call'
railties (4.2.4) lib/rails/application.rb:165:in `call'
railties (4.2.4) lib/rails/railtie.rb:194:in `public_send'
railties (4.2.4) lib/rails/railtie.rb:194:in `method_missing'
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
passenger (5.0.20) src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:94:in `process_request'
passenger (5.0.20) src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:151:in `accept_and_process_next_request'
passenger (5.0.20) src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:112:in `main_loop'
passenger (5.0.20) src/ruby_supportlib/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
passenger (5.0.20) src/ruby_supportlib/phusion_passenger/utils.rb:112:in `block in create_thread_and_abort_on_exception'
您可以粘貼您使用的curl命令 – Phil
@Phil我在您的development.log中爲您添加了示例cURL請求 – Josh
,您是否在請求中的任何地方看到它嘗試並且無法訪問數據庫記錄,或者它是否在路由階段完全失敗?例如,在驗證中引發404時,我似乎將事件顯示爲RoutingError。也許你可以提供一個顯示這個請求模式的rake路由片段? – Phil