I have a model named CustomFields that belongs to a main class (that has_many :custom_fields). This model has the attributes contents
and datatype
. I want the contents to be either a string or a uploader using carrierwave, according to the datatype of the object. I've done the following:
class CustomField < ActiveRecord::Base
after_initialize :set_uploader
def set_uploader
if self.datatype == 'file'
CustomField.mount_uploader :contents, ImageUploader
end
end
end
It's not working because it's turning all the object's contents into uploaders, not only the 'file' datatype. How can I solve that?