You want to use self.class.count. Self is a reference to the object it's self (in your case, an instance of FirePrevention), self.class is reference to the class.
On Jun 16, 9:32 pm, Mauro <[email protected]> wrote: > On 16 June 2011 21:24, Walter Lee Davis <[email protected]> wrote: > > > > > On Jun 16, 2011, at 4:15 PM, Mauro wrote: > > >> I want to assign a progressive number to an attribute. > >> I think that I can do this in the model > > >> class Model < ActiveRecord::Base > >> before_validation(:on => :create) do > >> attribute = Model.count + 1 > > >> But there is no method count for Model. > > > Is Model just an example, or did you use that as your model name? > > The real code is: > > class FirePrevention < ActiveRecord::Base > default_scope :order => 'practice_number ASC' > before_validation(:on => :create) do > practice_number = self.count + 1 > end > > It says undefined method count........... -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

