Uninitialized Constant Model When Plural Is The Same As Singular

Posted by Weston Ganger

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:

Article Topic:Software Development - Rails

Date:September 19, 2015

Recommended Posts

Contact

604-309-8713
info@solidfoundationwebdev.com

Send Me A Message

I would love to get in touch and talk about your next project. Feel free to send a message and I will get back to you shortly.

Get Connected