Rails engine refers to startup

I have engine 'Core' rails and I have:

# core/app/models/core/concerns/user_helper.rb module Core module UserHelper extend ActiveSupport::Concern included do # some methods end end end # core/app/models/core/user.rb module Core class User < ActiveRecord::Base include Core::UserHelper end end 

however, it says the uninitialized persistent Core :: UserHelper . Thus, it seems that the engine does not load its problems by default, so I added it in the startup path

 module Core class Engine < ::Rails::Engine config.autoload_paths += %W(#{Core::Engine.root}/app/models/core/concerns) isolate_namespace Core end end 

And now I am ending this error: It is not possible to automatically load the user UserHelper expected by myapp / core / app / models / core / issues / user_helper.rb to determine it

So what is wrong here? When I checked the explorer http://edgeguides.rubyonrails.org/engines.html and it had no problems in the problems directory, but rather the lib / problems had all the link to the concern about using Core :: Concerns :: MyConcern, so this is where to put problems in the engine?

thanks

Edit

Yuri’s comment explained this problem, it seems that the directory does not receive any special treatment on the problem engines, and it is considered as a regular directory under the models, so the modules in it should be in the Concerns namespace and when you enable anxiety, you should include it also in "Concerts", if I understand correctly. I am surprised that this is not mentioned in the docs.

+13
ruby-on-rails rails-engines
source share
2 answers

Concern should be inside applications / models | controllers / problems / computer_name / organization_name .rb. This will enable the autoload problem.

To enable the problem, enable EngineName :: ConcernName.

+22
source share

I had the same problem. Your mistake is that you put the concerns directory in the app/{models|controllers}/core directory if that is not the case.

Instead of doing

app/{models/controllers}/core/concerns/user_helper.rb

change it to be

app/{models/controllers}/concerns/core/user_helper.rb

It took me a little time to understand, because I intuitively thought that this should also be in engine_name .

Hope this helps.

0
source share

All Articles