Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

Ruby on rails.Generating controller

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)

question from:https://stackoverflow.com/questions/65648888/ruby-on-rails-generating-controller

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...