0

Why when I write rails generate controller home index the index.html.erb file is not created in the views folder? And when I run rails server and want to watch http://127.0.0.1:3000/home/index terminal output.

Started GET "/home/index" for 127.0.0.1 at 2021-01-10 01:54:30 +0200 Processing by HomeController#index as HTML Completed 204 No Content in 0ms (ActiveRecord: 0.0ms | Allocations: 60)

1

1 Answer 1

1

When I check error log I see HomeController#index, I would like you to check rails routes first. You should see a result similar to this:

Prefix      Verb   URI Pattern            Controller#Action

home_index  GET    /home/index(.:format)  home#index
...

If you are seeing homecontroller#index instead of home#index you can access by going to related URI pattern.

You can control which files are created when you run rails generate command. This is a sample output:

➜ rails g controller home index    
Running via Spring preloader in process 1934
      create  app/controllers/home_controller.rb
       route  get 'home/index'
      invoke  erb
      create    app/views/home
      create    app/views/home/index.html.erb
      invoke  helper
      create    app/helpers/home_helper.rb
      invoke  assets
      invoke    scss
      create      app/assets/stylesheets/home.scss

As you see there is a file app/views/home/index.html.erb make sure that it is not empty. For example put <p>Home</p> in this file, if it is empty.

I hope it is clear enough and I think this will solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.