ruby - Rails engine doesn't eagerly load app files while seeding db -
i'm trying add together install task mountable engine units.
the task loads seed, , within clears table:
# lib/tasks/units_tasks.rake namespace :units task :install units::engine.load_seed end end # db/seeds.rb units::item.delete_all ... when phone call task command line
$ bundle exec rake units:install # => nameerror: uninitialized constant units::item the engine required usual (and gem works fine dependencies except case above).
# lib/units.rb require 'units/engine' module units end # lib/units/engine.rb module units class engine < ::rails::engine isolate_namespace units end end obviously loaded without files, should eagerly loaded. why?
in seed method, need
require_relative '../lib/units' or potentially
require_relative '../lib/units/engine' then should able namespace have been previously.
i believe has threadsafe nature of rails, more technical reason beyond me.
ruby-on-rails ruby load rails-engines seed
No comments:
Post a Comment