I'm using Rails 4.0.2. I added sub directories (with model names) in Concern directory:
cache_concern.rb in company directory had following content:
module Company::CacheConcern
included do
...
end
end
In my models class I had:
class Company
include Company::CacheConcern
...
end
Everything was fine till I went to production. Then I got following Exception:
`load_missing_constant': Circular dependency detected while autoloading constant Company::CacheConcern (RuntimeError)
To solve my problem I Change namespace in my concern files from Company::CacheConcern to Concerns::Company::CacheConcern. This allows me to load application in production enviroment.
But now I have problem in development enviroment in concern file in line where I'm using Company class:
NoMethodError (undefined method `current_company' for Concerns::Company:Module):
So it looks like he is searching in Concern directory. In production everything is fine. To resolve this problem I could add in concern files two colons before class name to use the class from models directory.
I know production mode does not behave the same way as development, because of caching whole app in memory. I checked all similar posts. Do I need to precede class names from model directory with two colons in concern files? I would be very grateful if someone could explain me this strange situation.
Thanks
You did this I think it is wrong: To solve my problem I Change namespace in my concern files from Company::CacheConcern to Concerns::Company::CacheConcern. This allows me to load application in production enviroment.
Instead do this
Companies::CacheConcern and rename your folder as companies/cache_concern.rb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With