Activerecord(mysql) and hash to unique count

I am working with ruby(activerecord) and want to save a ‘hash’ of URLs
such that a key is the URL and the value points to a count of how many
times it occurs after processing a csv file
my question; all I know of is right now is to attempt to save, get a
unique error and then when handling the exception increment the hash
value (really a column in a table)

Is this bad? Or are there better ways?

word =
word.word = w.strip
word.source = url_source

  puts "ERR: Could not save system word (possible unique error)"
  # Potentially, we need to update the record
  found = NumbersWord.find(:first, :conditions => [ "word = ?", w ],

:limit => 1)
if found
found.occurrence = found.occurrence + 1

  # End of Exception


Berlin B.
(ramaza3 on freenode)
also checkout alpha version of botverse:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs