This is possible but a little convoluted. Essentially when you save a record of an inherited class, the method moves up to the parent class with an added 'type' value.
The standard definition:
class Vehicle < ActiveRecord::Base
..
def type=(sType)
end
..
end
class Truck < Vehicle
# calling save here will trigger a save on a vehicle object with type=Truck
end
Changing this is precarious at best in my opinion. You'll likely run into other issues.
I recently discovered AR method becomes which should allow you to morph children objects into parent objects or as the documentation suggests parents into children, you might have some luck with that.
vehicle = Vehicle.new
vehicle = vehicle.becomes(Truck) # convert to instance from Truck to Vehicle
vehicle.type = "Truck"
vehicle.save!
Not used this myself, but simply, you should be able to change the type
column value before saving rather easily. This will likely cause a few problems with the inbuilt Active Record query interface and associations.
Also, you can do something like:
class Truck
..
def self.model_name
"MyNewClassName"
end
..
end
But with this approach beware that the rest of rails, including routes and controllers will refer to the model as "MyNewClassName" and not "Truck".
PS: If you can't add classes inside your Global Namespace then why not add them inside another namespace? The parent and child can belong to different namespaces or can both belong to a unique namespace (not the global).