On Feb 11, 8:45 am, Frederick Cheung <frederick.che...@gmail.com> wrote: > On Feb 11, 1:37 pm, Tony Primerano <tony.primer...@gmail.com> wrote: > > > I have a model and I set defaults for some values by overriding the > > read accessor. For example > > > def heading > > read_attribute(:heading).nil? ? 'Please select from:' : > > read_attribute(:heading) > > end > > Have you double checked this works by calling heading directly on the > object in question?
yes. This works <%= f.text_field :heading, :value => @site.heading %> and if I set it in the controller it works fine too. @site.heading = 'testing' Maybe text_field is using read_attribute instead of calling the method? > > Fred > > > > > The problem I have found is that text_field ignores this. > > > <%= f.text_field :heading %> > > > is empty even when heading is nil > > > now I can easily add :value and it works > > > <%= f.text_field :heading, :value => @site.heading %> > > > but it seems like this shouldn't be necessary. I also override read > > accessors for values that I use in select statements on the same form > > and it works fine. > > > def text_color > > read_attribute(:text_color).nil? ? SiteColors::TEXT_DEFAULT : > > read_attribute(:text_color) > > end > > > <%= f.select :text_color, SiteColors::COLORS%> > > > This picks up the default fine > > > Is this a bug in text_field or am I just doing something stupid? > > > Tony > > -- 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 rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.