Ask A Question

Notifications

You’re not receiving notifications from this thread.

Is it Ok to use "Error" as a model name in Rails project?

Alex Musayev asked in Rails

I have a simple question about class naming: is it Ok to use Error as a model name in a Rails project?

This model will be used to persist Ruby exception objects for errors monitoring. Using Exception as a name for this model doesn't look like a good idea, because it will collide with stdlib's Exception.

I've started using Error for the class name, but still not sure about this. There are seem to be no class with same name anywhere in stdlib and in the gems I'm using so far. But this is still a standard suffix for most Ruby and Rails exception class names, like StandardError.

Just want to be sure I'm not missing anything, like unexpected conventio-over-configuration gotchas.

Update: Errbit uses Err for a model name with pretty much the same purposes as mine (https://github.com/errbit/errbit/blob/master/app/models/err.rb). For mysterious reason.

Reply

Alex,

I think you are safe using Error has a class/model name as it doesn't collide with stdlib in Ruby or Rails. In fact I have a similar model in one of my older apps and it never caused issues.

If it doesn't feel right, then maybe you can change it to something like ErrorMessage or something like that, but I don't see it being an issue although others may be able to chime in with better intel.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.