[LRUG] Query about ActiveRecord

Craig Webster craig at xeriom.net
Fri Aug 17 11:05:34 PDT 2007


On 17 Aug 2007, at 18:58, John Winters wrote:
> class Cycle < ActiveRecord::Base
>
>    def pattern
>      @pattern
>    end
>
>    def pattern=(new_pattern)
>      #
>      # Pad new_pattern to required length if needed, and then...
>      #
>      @pattern = new_pattern
>    end
>
> end
>
> Obviously you have to use @pattern and not self.pattern or you end up
> with a recursive call.

Use write_attribute('pattern', new_pattern), though I'd try to do it  
by using alias_method_chain like so:

class Cycle < ActiveRecord::Base
   def pattern_With_minimum_length=(pattern)
     # pad pattern here
     self.pattern_without_minimum_length = pattern
   end
   alias_method_chain :pattern, :minimum_length
end

Untested so I'm not sure if it'll work, but worth a try :)

About to get kicked out of Starbucks (closing time) or I'd explain  
what was causing the problem more throughly so err... it's left a an  
exercise to the reader!

Cheers,
Craig
--
Craig Webster   | Lead Developer   | skype: craigwebster
Xeriom Networks | t: 0131 208 3800 | w: http://xeriom.net/

  -- Virtual machines, dedicated servers and colocation --

Xeriom Networks Limited.
94/1 Spring Gardens, Abbeyhill, Edinburgh, Scotland.
Registered in England and Wales. Company No. 5961686.

All agreements are made under our standard terms and conditions.
These can be found at http://xeriom.net/terms_and_conditions





More information about the Chat mailing list