I’m trying to get a method in place that registers link clicks. After reading about this subject and trying a lot I don’t get it to function. My best try, which does not work, is <%= link_to person.name, person_url, :method => :count_new %>. The person_url is the url I want people who click the link should go to. The count_new method looks like this:
stat = Stat.find_by_country(params[:country])
stat = stat.download+=1
stat.save
The params[:country] is in the url.
I know update_attributes works better but I’ll get to that later.
I looked into counting the views on the person_url page but I really want to register clicks from different links in stead of registering views on the actual page user go to.
I’m on rails 3.
Any help is appreciated.
Rutger
You’re trying to save an integer to your stat model when you should be updating its attribute, download (I assume).
Edit
Your link_to looks off:
have this in your routes to make this work:
also add rails 3 javascript helpers for the remote => true call:
http://asciicasts.com/episodes/205-unobtrusive-javascript