Hello, I''ve got a model with an attribute that I''ve overridden -- or at least defined an implementation for. It seems that when I call form.text_field :foo, it''s grabbing foo out of the attributes hash in the object rather than calling the method. I can get around this by using text_field_tag :foo, @object.foo. Is that cool, or is there a better way? It seems interesting that text_field would grab stuff directly out of the attributes hash, thereby assuming my implementation. If they called the method ''foo'' it would preserve my implementation. Then, if there wasn''t an implementation, ActiveRecord would step in and handle things. Thanks! Mark --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
what does your implementation look like? something like this ought to work as expected: class Foo def foo "custom value of #{self[:foo]}" end end On Jul 30, 10:40 am, "Mark Veerman" <markveer...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello, > > I''ve got a model with an attribute that I''ve overridden -- or at least > defined an implementation for. It seems that when I call > form.text_field :foo, it''s grabbing foo out of the attributes hash in > the object rather than calling the method. I can get around this by > using text_field_tag :foo, @object.foo. > > Is that cool, or is there a better way? It seems interesting that > text_field would grab stuff directly out of the attributes hash, > thereby assuming my implementation. If they called the method ''foo'' it > would preserve my implementation. Then, if there wasn''t an > implementation, ActiveRecord would step in and handle things. > > Thanks! > Mark--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hello, On Jul 30, 10:54 pm, jemminger <jemmin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> what does your implementation look like? > > something like this ought to work as expected: > > class Foo > def foo > "custom value of #{self[:foo]}" > end > endThanks for the response. That''s exactly what I was doing. I have a plugin that defines an implementation for foo like you describe. We did figure out what was going on though. For each model attribute in Rails there''s another method called value_before_type_cast. In the case of your example: the attribute foo would have two Rails ''MethodMissing'' getters: foo, and foo_before_type_cast. It seems that the text_field API uses the latter, so my implementation for foo was never called. We solved the problem by implementing foo_before_type_cast and having it call through to foo. I''m not sure if that''s the best way, but it works and makes sense. I don''t really know why there is that other before_type_cast method, or why text_field seems to prefer it. Thanks, Mark --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---