>> increment() will *overwrite* the value in the database, not add to it. > > Ah! That's the bit that wasn't clear to me the way you phrased it > before. Reading your post again, I can see what you mean now.
The annoying thing is that if your site doesn't get much traffic increment() will appear to work. It's only when there's concurrent access that it will start to break down. This next part is for the archives... As a general rule, if you are incrementing or decrementing fields that are counters, do not use any Rails method that *set* the value and save it. Make sure the method results in a "UPDATE table SET c = c + 1" type of query. If you write your own implementation, be sure to consider the situation in which your database column is NULL. And if you're doing a lot of this, you might find this useful http://github.com/phallstrom/set_counters as well. Or not :) -philip -- 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.

