Ruby on Rails ルーティングエラー

Ruby on Rails ルーティングエラー

Ubuntu DropletでRuby on Railsを実行していますが、ドメイン名に移動すると次のエラーが発生します。

Routing Error
uninitialized constant HomeController
Rails.root: /home/rails/example

Application Trace | Framework Trace | Full Trace
Routes
Routes match in priority from top to bottom

Helper      HTTP Verb   Path    Controller#Action
Path / Url     GET       /         home#index
root_path       

走ってみました。

rails g controller home index

しかし、広範なエラーが発生します。以下はエラーの最初の数行です。

/home/rails/example/config/routes.rb:6:in `block in <main>': undefined local 
variable or method `map' for # . 
<ActionDispatch::Routing::Mapper:0x00007f11683c6fd8> 
Did you mean? tap (NameError) 
from /root/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack- 
5.2.1/lib/action_dispatch/routing/route_set.rb:432:in `instance_exec' 
from /root/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/actionpack- 
5.2.1/lib/action_dispatch/routing/route_set.rb:432:in `eval_block'

関連ファイルツリーは次のとおりです。

app
  -controllers
    -application_controller.rb
bin
config
  -routes.rb

application_controller.rbの内容は次のとおりです。

class ApplicationController < ActionController::Base
end

Routes.rbの内容は次のとおりです。

Rails.application.routes.draw do
root to: 'home#index'


 Place at the end of the routing!
map.root :controller => 'MyController', :action => :index

end

ベストアンサー1

問題は、パスが存在しないコントローラを指していることです。

Rails.application.routes.draw do
#root to: 'home#index'


# Place at the end of the routing!
#map.root :controller => 'MyController', :action => :index

end

これをコメントアウトすると、コマンドは再び機能します。

おすすめ記事