Forum: Ruby on Rails Strange behavior when override a default attribute, maybe a bug?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
89e57a28dfdb85e07b33f92783dbe349?d=identicon&s=25 Daniel Lopes (Guest)
on 2008-12-17 22:15
(Received via mailing list)
Hello, I have a strange behavior and don't know why.

If I override attributes from AcitveRecord object like below:

  def end_date=(date)
    date = date.to_date unless date.blank?
    write_attribute(:end_date,date)
  end

  def end_date
    date = read_attribute(:end_date)
    I18n.localize(date) if date.present?
  end

Everything will work fine but when I try call text_field in a form_for
block I get the database value and ignore end_date getter.

<%= f.text_field :end_date, :class=>"date", :size=>"10" %>

The text_field will be filled with 2008-12-10 (mysql date) instead of
10/12/2008 ( I18n localized)

Anyone know why we get this behavior?
89e57a28dfdb85e07b33f92783dbe349?d=identicon&s=25 Daniel Lopes (Guest)
on 2008-12-18 02:15
(Received via mailing list)
Some idea? I still don't understand why text_field load values from
database instead of model.rb
89e57a28dfdb85e07b33f92783dbe349?d=identicon&s=25 Daniel Lopes (Guest)
on 2008-12-18 02:51
(Received via mailing list)
Sorry for duplicated threads, it was a mistake, I opened new one here
http://groups.google.com/group/rubyonrails-talk/br...
...
This topic is locked and can not be replied to.