The String#constantize
method is a feature that makes rails fun to code with. This method converts a string to the constant that the string contains (or throws a NameError
if there is no such constant). It makes it easy to store class-types in databases as strings and to code controllers that work with classes of the same duck type.
Most people know that eval
on user data is dangerous, but noboddy seems to care about constantize
. Beware, it is also dangerous and you should constantize with care!
Continue reading