# Rails Class Collisions

> Working around Rails generator errors when existing constants collide with generated class names

- Author: Curtis Miller
- Published: 2008-08-24
- Categories: rails, how-to
- Canonical URL: https://millarian.com/posts/rails-class-collisions/

While trying to use the oh-so-nifty [missing spec finder](https://millarian.com/posts/discover-your-missing-specs/) on a recent project, I discovered that it was not working. Hmmm… seems that somewhere along the way Rails added detection for existing constants and won't allow you to re-generate something. Instead it calls `raise_class_collision`, which raises a `UsageError`. Damn them.

Anyway, to work around this for now, you can add the following somewhere (e.g., an initializer):

```ruby
require 'rails_generator/base'
require 'rails_generator/commands'

module Rails
  module Generator
    module Commands
      class Create
        def raise_class_collision(class_name)
          # Do Nothing
        end
      end
    end
  end
end
```

This should get around that inconvenience. Plus, you won't be exposed to nefarious suggestions like I was:

```bash
$ rake spec:sync
  The name 'User' is either already used in your application or reserved by Ruby on Rails.
  Please choose an alternative and run this generator again.

  Suggestions:

exploiter
drug user
substance abuser
```

Thanks Rails, you're so helpful! I just don't understand how it could have known I was building a Facebook clone for junkies…

## Other Resources

- [Rails Ticket #545: Bug colliding classes (when they shouldn't)](http://rails.lighthouseapp.com/projects/8994/tickets/545-bug-colliding-classes-when-they-shouldn-t)
- [resource\_controller Google group: Reserved resource names?](http://groups.google.com/group/resource_controller/browse_thread/thread/99025ab805c78141)
