简体   繁体   中英

Ruby on Rails 5

I've moved all my controllers, helpers, models, views and assets under a web folder. And now I'm getting an uninitialized constant HomeController error. How can I reflect this change to my routes?

Routes

Rails.application.routes.draw do
  root 'home#index', module: 'web'
end

在此处输入图片说明

uninitialized constant HomeController

You have root 'home#index', module: 'web' and as you moved your controller under the web, the class name of the controller should be prefixed with module name like Web::

class Web::HomeController
end

OR

If you wish not to prefix with Web:: module, you can just change

root 'home#index', module: 'web'

to

root 'home#index', path: '/web/home'

For more info read Controller namespacing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM