I have a Rails engine with the latest rails and ruby.
I have a controller called cms, with a action called update. I use this update action to update different tables. For example I have got a table called setting. This technique works fine in a normal Rails app, but in my Rails Engine it throws this error:
NameError (uninitialized constant Setting):
I’ve got a model called Setting, why is givin me an error ?
File naming is important for autoloading to work. Naming convention is the same in both apps and engines. In fact, an application is an engine.
So,
my_rails_app/app/models/cms/setting.rbis equivalent tomy_engine/app/models/cms/setting.rbIf you still have troubles, try accessing constant with explicit namespace
Cms::Setting.You can dynamically get constant from an appropriate namespace by doing
However, be careful with this approach since a hacker can send you anything and hence access any constant.