Herman Müller
2009-Jul-08 20:53 UTC
date as textfield, virtual attribute can''t be empty?
Hi Ruby comunity! I made a virtual date attribute to input date into a textfield. Here is my entry from models\tbl_data.rb: def date_test_string date_test.strftime(''%d.%m.%Y'') end def date_test_string=(date_test_str) self.date_test = Date.strptime(date_test_str, ''%d.%m.%Y'') rescue ArgumentError @date_test_invalid = true end def validate errors.add(:date_test, "is invalid") if @date_test_invalid end My Problem is, when I try to input no date (empty textfield) the validation throws an error --> invalid date. When I disable "def validate" there is no error-message but the new emtpty date will not be saved into the database, the old date (like 01.01.2009) appears again in the "show" page. Do somebody knows where I did go wrong? Thanks ahead for every suggestion!! Regs, Hermann -- Posted via http://www.ruby-forum.com/.