简体   繁体   中英

rails admin uninitialized constant Country::Person

When I click on Countries in rails_admin navigation I get

NameError in RailsAdmin::Main#index

uninitialized constant Country::Person

raise NameError.new("uninitialized constant #{candidates.first}", candidates.first)

I'm using User model but not Person. I think I need to configure it somehow. But where to do this?

here's my rails admin initializer

  ## == Devise ==
   config.authenticate_with do
     warden.authenticate! scope: :user
   end
   config.current_user_method(&:current_user)

  ## == Cancan ==
   config.authorize_with :cancan 

  ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration

  config.model "User" do
      edit do
        field :admin
        field :username
        field :email
        field :password
      end
    end

  config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new
    export
    bulk_delete
    show
    edit
    delete
    show_in_app

    ## With an audit adapter, you can add:
    # history_index
    # history_show
  end

The problem was with my model. it used to be

class Country < ActiveRecord::Base
  has_many :people
end

I had this issue too, but it wasn't caused by a lost association. I had incorrectly pluralized my model's name when I created it: it was Things instead of Thing .

I fixed it manually by changing the class name in things.rb from Things to Thing and renaming the file to thing.rb .

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