Uninitialized constant “Controller Name”

前端 未结 4 1752
终归单人心
终归单人心 2021-01-17 08:13

I\'m having an error with my routes/resources and controllers.

I have the following in the routes.rb:

# routes.rb
resources :users do  
  resource :s         


        
4条回答
  •  不知归路
    2021-01-17 08:27

    Is the namespacing of the SchedulesController intentional? i.e. do you really mean to do this?

    class Users::SchedulesController < ApplicationController
    

    Or are you only doing that because schedules are a "sub-thing" from users?

    The reason I ask this is because typically within Rails, nested resource controllers aren't namespaced. You would only namespace a controller if you wanted to modify the controllers in a special way under a namespace. A common example of this would be having some controllers under an admin namespace, inheriting from a BaseController within that namespace that would restrict only admins from acessing those controllers.

    Option 1

    If you didn't intentionally namespace this controller, then you want to remove the Users:: prefix from your controller, and move it back to app/controllers/schedules_controller.rb, the helpers back to app/helpers/schedules_helper.rb and the views back to app/views/schedules. Perhaps you ran a generator which also generated a Users::Schedule model, which should also need to be renamed to Schedule and moved back to app/models/schedule.rb.

    Option 2

    If you did intentionally namespace this controller, then you want to do this in your routes:

    namespace :users do
      resources :schedules
    end
    

    Leave everything that's been generated as it should be.

提交回复
热议问题