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 initialized:
@user = User.new(params[:user])
to the moment it saved
@user.save
anyone else can create user object(s), so your @user will be saved with
incorrect counter value.
--
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.