From: Gregory Brown Date: 2008-08-05T06:09:00+09:00 Subject: Re: Still missing the boat on class/instance methods On Mon, Aug 4, 2008 at 4:55 PM, laredotornado wrote: > Hi, > > Yesterday the group was kind enough to explain distinctions between > class and instance methods, but I guess I still missed something b/c > I'm getting an error. I have this method in my EcOrder model ... > > class EcOrder < ActiveRecord::Base > has_many :ec_line_items > validates_associated :ec_line_items > > ... > def has_item=(form_item_id) > for ec_line_item in this.ec_line_items > if ec_line_item.form_item_id == form_item_id > true > return > end > end > false > end > end You defined an attribute writer but I think you want a conditional check. Note that 'this' is not valid ruby syntax, you're looking for self, but it's usually not necessary. Using pure Ruby: def has_item?(item_id) ec_line_items.any? { |e| e.form_item_id == item_id } end But you probably want to do that check using ActiveRecord, probably a find with some conditions. That's Rails stuff though, and would much better be handled over on the Ruby on Rails - Talk mailing list. -greg -- Killer Ruby PDF Generation named after a magnificent sea creature: http://github.com/sandal/prawn | Non-tech stuff at: http://metametta.blogspot.com