计算链接点击次数
我正在尝试找到一种注册链接点击的方法。在阅读了这个主题并尝试了很多之后,我无法让它发挥作用。我最好的尝试是 <%= link_to person.name, person_url, :method => ,但不起作用。 :count_new %>
。 person_url 是我希望点击该链接的人应该访问的 url。 count_new 方法如下所示:
stat = Stat.find_by_country(params[:country])
stat = stat.download+=1
stat.save
params[:country] 位于 url 中。 我知道 update_attributes 效果更好,但我稍后会讲到。
我研究了计算 person_url 页面上的视图,但我真的想注册来自不同链接的点击,而不是注册用户访问的实际页面上的视图。
我在 Rails 3 上。
如有任何帮助,我们将不胜感激。
罗格
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您应该更新其属性时,您正尝试将整数保存到统计模型中,下载(我假设)。
编辑
您的 link_to 看起来不太好:
在您的路线中添加此内容以使其正常工作:
还为远程添加rails 3 javascript helpers =>真正的调用:
http://asciicasts.com/episodes/205-unobtrusive-javascript
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