Rails Class Collisions
While trying to use Integrum’s oh-so-nifty missing spec finder 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):
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:
$ 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)
- resource_controller Google group: Reserved resource names?
More of my rantings
These might also interest you
- Can I speak with your supervisor? (Brainfuel)
- Why I heart Zipcar (Horse Pig Cow)
- Real Estate Investment v. Tech Investing (Stealthmode)







