0
我跟着一些教程來爲我的應用程序創建一個API。我把從Devise註冊和會話控制器繼承的自定義控制器。我瀏覽了大量的問題/答案,無法解決我的問題。與初始化常量(NameError)與名稱空間的自定義Devise類
我的解決方案適用於我的Ubuntu VM,但不適用於ec2實例。下面是新一類的第一行:
class Api::V1::SessionsController < Devise::SessionsController
和routes.rb中的一些代碼:
devise_for :users
namespace :api do
namespace :v1 do
devise_scope :user do
post 'registrations' => 'registrations#create', :as => 'register'
post 'sessions' => 'sessions#create', :as => 'login'
delete 'sessions' => 'sessions#destroy', :as => 'logout'
end
get 'tournaments' => 'tournaments#index', :as => 'tournaments'
end
end
我定製的控制器是在API/V1目錄,並正確顯示路由。錯誤的是(與軌跡的一部分):
ActionController::RoutingError (uninitialized constant Api):
activesupport (3.2.13) lib/active_support/inflector/methods.rb:230:in `block in constantize'
activesupport (3.2.13) lib/active_support/inflector/methods.rb:229:in `each'
activesupport (3.2.13) lib/active_support/inflector/methods.rb:229:in `constantize'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:69:in `controller_reference'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:54:in `controller'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:32:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/mapper.rb:42:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call'
rack-pjax (0.7.0) lib/rack/pjax.rb:12:in `call'
mongoid (3.1.4) lib/rack/mongoid/middleware/identity_map.rb:34:in `block in call'
mongoid (3.1.4) lib/mongoid/unit_of_work.rb:39:in `unit_of_work'
mongoid (3.1.4) lib/rack/mongoid/middleware/identity_map.rb:34:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'
remotipart (1.2.1) lib/remotipart/middleware.rb:27:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
並獲取服務器的運行,我曾在applications.rb設置這些標誌:
# Code is not reloaded between requests
config.cache_classes = false
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
感謝您的建議。看起來我仍然得到同樣的錯誤。 –
編輯我的回答 – Benj
這樣做!非常感謝您的跟蹤。當它不是我的Ubuntu VM上的問題時,能夠深入瞭解爲什麼在這裏有效? –