Ubuntu

Ruby on Rails 路由錯誤

  • October 5, 2018

我在 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

問題是路由指向不存在的控制器。

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


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

end

將它們註釋掉應該讓命令再次工作。

引用自:https://unix.stackexchange.com/questions/473407