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

이를 주석 처리하면 명령이 다시 작동하게 됩니다.

관련 정보