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/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to