# Trying to create a counter for a link being clicked

**URL:** <https://www.ruby-forum.com/t/trying-to-create-a-counter-for-a-link-being-clicked/145871>\
**Category:** Rails\
**Created:** [August 14, 2008, 5:10pm UTC](https://www.ruby-forum.com/t/trying-to-create-a-counter-for-a-link-being-clicked/145871 "2008-08-14T17:10:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brads](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@brads](https://www.ruby-forum.com/u/brads)\
**Post date:** [August 14, 2008, 5:10pm UTC](https://www.ruby-forum.com/t/trying-to-create-a-counter-for-a-link-being-clicked/145871/1 "2008-08-14T17:10:31Z")

</div>

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.
