From: Tim Hunter Date: 2008-08-04T06:59:29+09:00 Subject: Re: Why am I getting "undefined method" error? laredotornado wrote: > Hi, > > I have a model, in which I have defined a method ... > > class Form < ActiveRecord::Base > has_many :form_items > validates_associated :form_items > > ... > > def self.has_items > FormItem.count(:all, :conditions => ["form_id > = ?", :id]) > end > end > > > but when i try and call this method from another class, > > def new > @form = Form.find_by_user_id(session[:user_id]) > if (@form == nil) > false > else > @form.has_items > end > end > > > I'm getting the error below: > > undefined method `has_items' for # > > Any ideas? Thanks, - Dave > > By adding "self." to the has_items method definition, you've defined it as class method, but @form is an instance of Form. If you want to call has_items on an instance, remove the "self." in the method definition: def has_items ... end -- RMagick: http://rmagick.rubyforge.org/