On 16 August 2011 09:45, Petr M. <[email protected]> wrote: > And what about helpers? > I would like to let users to enter date in the text field (faster then > 3x select), so value for some_object.date_attribute > should in f.text_field(:date_attribute) > be "21.7.2011" (not "2011-07-21"). > > I am using virtual atributes for now: > > def date_attribut_to_s > if self.date_attribute.kind_of?(Date) > return self.date_attribute.strftime("%d.%m.%Y") > else > return self.date_attribute > end > end > > def date_attribut_to_s=(maybe_date) > date=nil > > if maybe_date.blank? > self.date_attribute=nil > elsif mybe_date.kind_of?(Date) > self.date_attribute=maybe_date > else > begin > #some more complex date parsing required? > date = Date.strptime(maybe_date, "%d.%m.%Y") > rescue > self.errors.add(:date_attribute,"Invalid date") > end > self.date_attribute = date unless date.blank? > end > end > > and use it in view as f.text_field(:date_attribute_to_s) .
So what is the question? Colin -- 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.

