-1

I am running ruby on rails on an Ubuntu Droplet and I am encountering the following error when I navigate to my domain name:

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       

I have tried running

rails g controller home index

But I get an extensive error. These are the first few lines of the error:

/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'

This is the relevant file tree:

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

These are the contents of application_controller.rb

class ApplicationController < ActionController::Base
end

These are the contents of 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

closed as off-topic by roaima, user88036, RalfFriedl, Thomas, Isaac Oct 8 '18 at 6:10

  • This question does not appear to be about Unix or Linux within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Is there a constant "HomeController" in your code? I.e. in /home/rails/example/.... Can you provide the relevant code? – rudib Oct 5 '18 at 13:01
  • Do you mean the error log? – Cody Rutscher Oct 5 '18 at 19:29
  • @rudib can we open this in a chat? – Cody Rutscher Oct 5 '18 at 19:50
  • You must have a class HomeController defined somewhere in the code. Probably under ./controllers/home_controller.rb or similar. – rudib Oct 5 '18 at 20:08
  • No. There is not HomeController there. – Cody Rutscher Oct 5 '18 at 20:14
0

The problem is that the routes are pointing to non existing controllers.

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


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

end

Commenting them out should get the command working again.

Not the answer you're looking for? Browse other questions tagged or ask your own question.