There seems to be no single best practice.
(1) It seems that the standard config/routes.rb offers to process the root page (or home page / welcome page) using welcome#index . If you should be guided by this, then to generate the corresponding welcome#index controller / action, you can use the following command:
rails generate controller Welcome index
Then in config/routes.rb you can delete the GET route ( get "welcome/index" ) automatically added by the generator and put the root root route root 'welcome#index' (or root :to => 'welcome#index' in Rails < 4 ) at the top of the file, because it is likely to be your most popular route and should be found first.
Also remember to remove public/index.html in Rails < 4 .
(2) The official Ruby on Rails routing guide uses the PagesController . In fact, it offers pages#main , although it is more logical for me to switch to pages#home (because "home page" is a universal term / concept). In addition, this controller can handle other page-oriented actions, such as pages#about , pages#contact , pages#terms , pages#privacy , etc.
(3) The Ruby on Rails manual comes with static_pages#home and static_pages#help , etc. Although I don't like the idea of designating this controller as “static”. These pages are likely to still have some dynamic aspects, especially the homepage!
(4) Although it’s not discussed how to handle the home page, RailsCast # 117 on semi-static pages offers another set of display-only resources.
I feel preference 1 and / or 2. In the scenario "and" you can use welcome # index and pages # about etc., while in the scenario "or" you can use pages # home, pages # about, etc. If I had to choose, I would choose option 2 just because you have less code. And by the way, 2 and 3 are pretty much the same except for the word "static."
user664833 Jun 12 '12 at 19:52 2012-06-12 19:52
source share