2017-02-20 36 views
0

我剛開始接收到該錯誤的所有控制器。 不知道發生了什麼,因爲我在UI上工作,所以CSS,ERB文件,然後我重新加載頁面,並開始得到這個錯誤。無法自動加載恆定ApplicationController中(所有控制器)

感謝您的任何建議和幫助。

控制器:(應用程序/控制器/ ...)

home_controller.rb 
application_controller.rb 

在home_controller:

class HomeController < ApplicationController 
    def index 
    end 
end 

在application_controller:

class ApplicationController < ActionController::Base 
    protect_from_forgery with: :exception 
end 

路線:

Rails.application.routes.draw do 
    devise_for :admins, path: '', path_names: { sign_in: 'login', sign_out: 'logout'} 

    # HOME 
    root to: 'home#index' 

    # MESSENGER 
    match '/webhook', :controller => 'messenger', :action => 'callback', :via => :post 
    get '/webhook' => 'messenger#verify_callback' 
end 

錯誤:(除常數和路徑爲所有控制器相同的錯誤)

LoadError (Unable to autoload constant HomeController, expected /home/ubuntu/line/app/controllers/home_controller.rb to define it): 

activesupport (5.0.1) lib/active_support/dependencies.rb:512:in `load_missing_constant' 
activesupport (5.0.1) lib/active_support/dependencies.rb:203:in `const_missing' 
activesupport (5.0.1) lib/active_support/inflector/methods.rb:268:in `const_get' 
activesupport (5.0.1) lib/active_support/inflector/methods.rb:268:in `block in constantize' 
activesupport (5.0.1) lib/active_support/inflector/methods.rb:266:in `each' 
activesupport (5.0.1) lib/active_support/inflector/methods.rb:266:in `inject' 
activesupport (5.0.1) lib/active_support/inflector/methods.rb:266:in `constantize' 
activesupport (5.0.1) lib/active_support/dependencies.rb:583:in `get' 
activesupport (5.0.1) lib/active_support/dependencies.rb:614:in `constantize' 
actionpack (5.0.1) lib/action_dispatch/http/request.rb:81:in `controller_class' 
actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:44:in `controller' 
actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:30:in `serve' 
actionpack (5.0.1) lib/action_dispatch/journey/router.rb:39:in `block in serve' 
actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `each' 
actionpack (5.0.1) lib/action_dispatch/journey/router.rb:26:in `serve' 
actionpack (5.0.1) lib/action_dispatch/routing/route_set.rb:725:in `call' 
warden (1.2.7) lib/warden/manager.rb:36:in `block in call' 
warden (1.2.7) lib/warden/manager.rb:35:in `catch' 
warden (1.2.7) lib/warden/manager.rb:35:in `call' 
rack (2.0.1) lib/rack/etag.rb:25:in `call' 
rack (2.0.1) lib/rack/conditional_get.rb:25:in `call' 
rack (2.0.1) lib/rack/head.rb:12:in `call' 
rack (2.0.1) lib/rack/session/abstract/id.rb:222:in `context' 
rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call' 
actionpack (5.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call' 
activerecord (5.0.1) lib/active_record/migration.rb:553:in `call' 
actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call' 
activesupport (5.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__' 
activesupport (5.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks' 
activesupport (5.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks' 
actionpack (5.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call' 
actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call' 
actionpack (5.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call' 
actionpack (5.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call' 
web-console (3.4.0) lib/web_console/middleware.rb:135:in `call_app' 
web-console (3.4.0) lib/web_console/middleware.rb:20:in `block in call' 
web-console (3.4.0) lib/web_console/middleware.rb:18:in `catch' 
web-console (3.4.0) lib/web_console/middleware.rb:18:in `call' 
actionpack (5.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call' 
railties (5.0.1) lib/rails/rack/logger.rb:36:in `call_app' 
railties (5.0.1) lib/rails/rack/logger.rb:24:in `block in call' 
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `block in tagged' 
activesupport (5.0.1) lib/active_support/tagged_logging.rb:26:in `tagged' 
activesupport (5.0.1) lib/active_support/tagged_logging.rb:69:in `tagged' 
railties (5.0.1) lib/rails/rack/logger.rb:24:in `call' 
sprockets-rails (3.2.0) lib/sprockets/rails/quiet_assets.rb:13:in `call' 
actionpack (5.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call' 
rack (2.0.1) lib/rack/method_override.rb:22:in `call' 
rack (2.0.1) lib/rack/runtime.rb:22:in `call' 
activesupport (5.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
actionpack (5.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call' 
actionpack (5.0.1) lib/action_dispatch/middleware/static.rb:136:in `call' 
rack (2.0.1) lib/rack/sendfile.rb:111:in `call' 
railties (5.0.1) lib/rails/engine.rb:522:in `call' 
/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request' 
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request' 
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop' 
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads' 
/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception' 
    Rendering /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout 
    Rendering /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb 
    Rendered /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (3.1ms) 
    Rendering /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb 
    Rendered /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.3ms) 
    Rendering /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb 
    Rendered /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.8ms) 
    Rendered /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (20.3ms) 
Started POST "/webhook" for 66.220.152.184 at 2017-02-20 04:02:49 +0000 
Cannot render console from 66.220.152.184! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 

LoadError (Unable to autoload constant ApplicationController, expected /home/ubuntu/line/app/controllers/application_controller.rb to define it): 

app/controllers/messenger_controller.rb:3:in `<top (required)>' 
    Rendering /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout 
    Rendering /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb 
    Rendered /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (3.2ms) 
    Rendering /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb 
    Rendered /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.6ms) 
    Rendering /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb 
    Rendered /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.1ms) 
    Rendered /home/ubuntu/.rvm/gems/ruby-2.4.0/gems/actionpack-5.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (22.7ms) 
+0

什麼都改變......你能告訴我們什麼? – Milind

+0

CSS和HTML沒有什麼可以影響整個應用程序的只需要幾行..我試圖扭轉改變,仍然得到同樣的錯誤 – liborza

+0

告訴我你的routes.rb請 – Milind

回答

0

我使用C9和SSH的AWS服務器。該問題是在C9,因爲它不同步的文件很好,所以當我關閉文件和重新打開它,文件是空的..

如果有人使用C9,並且會遇到和我一樣的問題。

0

這不是一個路徑問題。這個問題是一個恆定的分辨率問題(加上自動加載),因爲它是說這是沒有找到在home_controller.rbHomeController類,儘管它的定義存在的事實。

嘗試重新啓動服務器進程。即使自動載入應該處理對類的任何更改,但有時我會看到它失敗。我也看到了與spring預加載器相同的問題。

如果這不起作用,您可以告訴我們您是否使用IDE,如果您嘗試在控制檯中與ApplicationController類進行交互,會發生什麼情況。

+1

好吧,我要去嘗試,明天因爲我剛剛離開辦公室..但感謝有關問題的解釋和細節。 – liborza

+0

我試圖重新啓動服務器,但我仍然得到相同的錯誤,使用NGINX和RMV for rails應用程序。順便說一句..你應該嘗試重新安裝那顆寶石嗎? – liborza

+0

@LiborZahrádka我不認爲這會是一個'春天'的寶石問題,它不會在開發中運行,我不認爲。 IDE也可能不相關。你可以彈出打開'軌道控制檯'並嘗試調用'ApplicationController'並看看會發生什麼? –

0

至於你提到你的所有控制器都讓這個錯誤,請檢查文件application.rb並添加此線或類似下面

config.autoload_paths += %W(#{config.root}/controllers) 

以上可能是因爲你的application.rb你獲得一些這方面的變化錯誤這是防止它自動加載所有的控制器

+0

我在'application.rb'中試過了,但沒有任何變化 – liborza

+0

@Umar,這沒有幫助;它試圖從正確的路徑自動加載。我相信不包括'autoload_path'會生成標準的未定義常量錯誤。 –

相關問題