Uninitialized Constant Model When Plural Is The Same As Singular

Posted by Weston Ganger on September 19, 2015

I found it to be a major pain in the ass when a model name’s plural version is the same as singular(ex. Equipment)

I was getting wierd ‘unitialized constant’ errors when trying to call the model name which. This error was occuring in Rails 3.2 so it probably works better in newer versions of rails.

The solution is to force the namespacing like so:

@equipment = ::Equipment.find(params[:equipment_id])

The two colans(::) in front of the model name tells it to use the global namespace rather than the current namespace.

Related External Links:

Posted in Rails and Tagged with rails namespacing 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts