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

将它们注释掉应该可以使命令再次工作。

相关内容