Rails engine concerns autoload paths -
i have rails engine 'core', , have:
# core/app/models/core/concerns/user_helper.rb module core module userhelper extend activesupport::concern included # methods end end end # core/app/models/core/user.rb module core class user < activerecord::base include core::userhelper end end
however says uninitialized constant core::userhelper. seems engine doesn't load concerns default, added in autoload paths
module core class engine < ::rails::engine config.autoload_paths += %w(#{core::engine.root}/app/models/core/concerns) isolate_namespace core end end
and end error: unable autoload constant userhelper, expected myapp/core/app/models/core/concerns/user_helper.rb define it
so wrong here? when checked guide http://edgeguides.rubyonrails.org/engines.html , didn't have concerns in concerns directory, rather under lib/concerns , had reference concern using core::concerns::myconcern, put concerns in engine?
thanks
edit
yury comment explained issue, seems in rails engines concerns directory don't special treatment, , treated normal directory under models, modules in must within concerns namespace, , when including concern, have include concerns namesapace well, if understand right. 'm surprised not mentioned in docs.
the concern must reside inside app/models|controllers/concerns/engine_name/concern_name.rb. autoload concern.
to include concern, include enginename::concernname.
Comments
Post a Comment