Trying to create a counter for a link being clicked

hi

im trying to create a counter for each time a link is clicked, but new
links can be created, so somehow i need it a count value to be linked to
each link, so that only that the clicked countre increments by 1.

suppose i have

link1
link2
link3

i would like if link1 had been clicked 4 times, it to refer to link1,4
if a new link was created, then it begins at 0

similarly if a link is created the counter is removed from the hash.

i presume this may require a hash. ive been hacking down that road, but
not getting very far.

my controller:

def new

@testrun.start_date = DateTime.now
@testrun.count = $counter

 $counter += 1

end

this increments a counter, but will simply increment one count for all
links.

any help would be really appreciated!

thanks in advance.