开发者

How to increment a colums value, when a call and value both passed to another controller

I have two models, referral and user model.

Referral belongs_to User AND user has_one Referral

When a user signs up, they are given a unique referral, like this localhost:3000/absc where absc is the unique referral Id.

When another users visits, localhost:3000/absc, using the routes.rb I have extracted the Id as follow

match '/:ref_token' => 'user#new'
@ref_token = params[:ref_token]         #in users_controller.rb

Now I have a hits column in Referral, that should increment the value for referral id absc, f开发者_开发问答or each visit to the URL.

How can I do so elegantly.

This may seem trivial, but I'm still on my path to Ruby Enlightenment, and I seek your wisdom.


In your controller, simply do :

Referall.find_by_ref_token(params[:ref_token]).increment!(:hits)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜