Re: [Rails] Looking for a way to set a variable when doing Model.new

2012-02-08 Thread Peter Vandenabeele
On Wed, Feb 8, 2012 at 10:39 AM, Colin Law wrote: > On 8 February 2012 07:12, Bob Smith wrote: > > I need a way to set a counter that will show how many of the model > > have been created and put this in each instance. This will allow me to > > use the record number as an input to another field

Re: [Rails] Looking for a way to set a variable when doing Model.new

2012-02-08 Thread Valery Kvon
On 08.02.2012, at 15:05, grentis wrote: > You can use also after_initialize checking if the counter is already setted > > after_initialize :set_counter > > def set_counter > self.counter ||= ModelName.all.count > end Imagine 'create' action. During the period from the instance is initializ

Re: [Rails] Looking for a way to set a variable when doing Model.new

2012-02-08 Thread Valery Kvon
On 08.02.2012, at 13:39, Colin Law wrote: > On 8 February 2012 07:12, Bob Smith wrote: >> I need a way to set a counter that will show how many of the model >> have been created and put this in each instance. This will allow me to >> use the record number as an input to another field before id i

Re: [Rails] Looking for a way to set a variable when doing Model.new

2012-02-08 Thread Colin Law
On 8 February 2012 07:12, Bob Smith wrote: > I need a way to set a counter that will show how many of the model > have been created and put this in each instance. This will allow me to > use the record number as an input to another field before id is set. > After things are settled, the real id nu

[Rails] Looking for a way to set a variable when doing Model.new

2012-02-07 Thread Bob Smith
I need a way to set a counter that will show how many of the model have been created and put this in each instance. This will allow me to use the record number as an input to another field before id is set. After things are settled, the real id number can be substituted for the counter. I've tried