So, I have a model, and I''ve defined some non-persisted attributes. I''d like to augment the to_s to include these in to_s and other output statements (like whatever awesome print is calling). If possible, I''d like to augment the existing functionality (vs replacing it)? Is there a standard way to do this? I can probably figure out how to do this if someone could point me to where to_s is being defined in ActiveRecord. Thanks, -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/rgUP8LOyj1wJ. For more options, visit https://groups.google.com/groups/opt_out.
On 3 September 2012 17:27, John Hinnegan <john.hinnegan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So, I have a model, and I''ve defined some non-persisted attributes. I''d like > to augment the to_s to include these in to_s and other output statements > (like whatever awesome print is calling).What is it that you want to call to_s on? An instance of the model or the attribute itself? If the attribute then what class it is? If the model instance then just define to_s in your model class to do whatever you want. Colin> > If possible, I''d like to augment the existing functionality (vs replacing > it)? Is there a standard way to do this? I can probably figure out how to > do this if someone could point me to where to_s is being defined in > ActiveRecord. > > Thanks, > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/rgUP8LOyj1wJ. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
The model itself. So right now when you inspect, puts, etc on the model, it shows only the attributes which are persistent. I would like to augment it to also show my non-persisted attributes. This is for debugging purposes only. I''m guessing somewhere in ActiveModel or ActiveRecord, the to_s is being overridden. Is there a general way I can override so that to_s, inspect, and awesome_print will all show the non-persisted attributes? On Monday, September 3, 2012 9:42:58 AM UTC-7, Colin Law wrote:> > On 3 September 2012 17:27, John Hinnegan <john.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<javascript:>> > wrote: > > So, I have a model, and I''ve defined some non-persisted attributes. I''d > like > > to augment the to_s to include these in to_s and other output statements > > (like whatever awesome print is calling). > > What is it that you want to call to_s on? An instance of the model or > the attribute itself? If the attribute then what class it is? If the > model instance then just define to_s in your model class to do > whatever you want. > > Colin > > > > > If possible, I''d like to augment the existing functionality (vs > replacing > > it)? Is there a standard way to do this? I can probably figure out how > to > > do this if someone could point me to where to_s is being defined in > > ActiveRecord. > > > > Thanks, > > > > -- > > 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 rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:>. > > > To unsubscribe from this group, send email to > > rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. > > To view this discussion on the web visit > > https://groups.google.com/d/msg/rubyonrails-talk/-/rgUP8LOyj1wJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/cFHZVKSdHG0J. For more options, visit https://groups.google.com/groups/opt_out.