[LRUG] Query about ActiveRecord

Matthew Westcott matthew.westcott at torchbox.com
Fri Aug 17 11:03:52 PDT 2007


See "Overwriting default accessors" on http://api.rubyonrails.org/ 
classes/ActiveRecord/Base.html - the trick is to use  
write_attribute / read_attribute to work with the underlying  
attribute field.

- Matt

On 17 Aug 2007, at 18:58, John Winters wrote:
>  The way I've worked around it is to do:
>
> class Cycle < ActiveRecord::Base
>
>    def mpattern
>      self.pattern
>    end
>
>    def mpattern=(new_pattern)
>      #
>      # Pad new_pattern to required length if needed, and then...
>      #
>      self.pattern = new_pattern
>    end
>
> end
>
> and then change the name of the field in the view from "pattern" to
> "mpattern".  This works, but strikes me as messy.  Is there a more
> rails-correct way of doing it?




More information about the Chat mailing list