Rails

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 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts