0

I have a class App located in app/models/administration/app.rb

class App < ActiveRecord::Base
    #...
end

And a class App::Type located in app/models/administration/app/type.rb

class App
    class Type
        attr_reader :sym, :name
        ALL = [:type1, :type2]
        #...   
    end
end

My application is configured to autoload from app/models/administration directory

config.autoload_paths += %W(#...
                            #{config.root}/app/models/administration)

When I try to access App::Type::ALL from rails console, I get the following error

pry(main)> App::Type::ALL

NameError: uninitialized constant ActiveRecord::Type::ALL

Why is there a confusion between App::Type::ALL and ActiveRecord::Type::ALL and how can I fix it?

noscreenname
  • 3,314
  • 22
  • 30
  • 2
    see this thread: https://stackoverflow.com/questions/24352603/model-named-type-in-rails – eugenioy Jul 05 '17 at 18:46
  • @eugenioy So you just can't have a class named `Type` in rails? – noscreenname Jul 05 '17 at 20:09
  • Seems it would not be advisable to use that name, though the related answer suggests some workarounds if you really can't use a different name. I would call it AppType and forget about the issue :) – eugenioy Jul 05 '17 at 20:18

0 Answers0