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

def date_test_string=(date_test_str)
self.date_test = Date.strptime(date_test_str, ‘%d.%m.%Y’)
rescue ArgumentError
@date_test_invalid = true


def validate
errors.add(:date_test, “is invalid”) if @date_test_invalid

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!!



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs