I’m using Mongoid on Sinatra . And I use
Dir.glob(File.join(File.dirname(__FILE__),'models','*.rb')).each do |file|
require file
end
to load mongoid model files.
I tried to add a model B inherit from A ,like:
models/a.rb:
class A
include Mongoid::Document
include Mongoid::Timestamps
field :custom_id, type: Integer
end
models/b.rb
class B < A
field :title , type: String
field :body , type: String
end
But when I exec the App , I got errors :
uninitialized constant A (NameError)
So I’m trying to find a solution for this,
it could be fixed by add:
require A
at the top of model B , But I think it may not be a good way to solve it.
So , is there anyother way to fix this??
Regards
You just require your file where you A class is define.
Sinatra has no auto_load system like rails have. So you need doing all of your require needed.