I am working with a legacy database that has a bit of a design quirk. There is a column set to NOT NULL but that has a default value of "" (empty string). This is causing me issues when attempting to save to this column. Rails is automatically turning any attribute that is empty to nil.
my_class = MyClass.new
my_class.variable = ''
this will evaluate to nil, I understand the Rails convention is to send nil, it makes sense, but in this case I have to send the empty string for data integrity. How can I force ActiveRecord to actually save the empty string to the database?
Edit:
# Console
1.9.3-p484 :002 > my_class = TestClass.new
=> nil
1.9.3-p484 :003 > my_class.name = 'hello'
=> "hello"
1.9.3-p484 :004 > my_class.name
=> "hello"
1.9.3-p484 :005 > my_class.name = ''
=> ""
1.9.3-p484 :006 > my_class.name
=> nil
The attribute's getter will always return nil even when I set it as an empty string.