简体   繁体   中英

Uninitialized constant Admin (NameError)

I have little problem about my code I make controller/admin/moderators_controller.rb .

I got an error on compilator uninitialized constant Admin (NameError) in moderators_controller.rb .

In navigator I got this error:

superclass must be a Class (Module given) navigator error

class Admin::ModeratorsController < ActionController
  def index
  end
end

This is my routes.rb file:

Rails.application.routes.draw do
  namespace :admin do
    resources :moderators, only: [:index]
  end
end

You've accidentally made your controller inherit from ActionController (a module) instead of ActionController::Base (a class). You need to add ::Base to the end there.

If this is Rails 5, the common convention now is to have a ApplicationController class in your app/controllers folder, and have all controllers inherit from that (it's just a class that inherits from ActionController::Base , but gives you a place to put common methods).

Rails 5

class Admin::ModeratorsController < ApplicationController
  def index
  end
end

Rails 4 or below

class Admin::ModeratorsController < ActionController::Base
  def index
  end
end

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