0

I am working with merit gem and I have a pages controller and an action 'fan'. I need the merit gem to add 10 score when user be a fan of a page. Modal is 'Fan'. Fan has a user.

score 10, :on => 'pages#fans', model_name: 'Fan', :to => :user

But this is not working. Any idea?

Abhi
  • 3,361
  • 2
  • 33
  • 38
  • Did you define a `@fan` instance variable in the controller? It's possible you'll need a `@page` one, not exactly sure now on your case. – TuteC Jun 04 '14 at 14:06
  • No, `@fan` instance variable is not there in the controller. But `@page` is there. – Abhi Jun 05 '14 at 04:47
  • I don't think you need the `model_name: 'Fan'` option then. – TuteC Jun 05 '14 at 14:56
  • I am manually giving the score now. Nothing given in the point_rules.rb is giving scores. – Abhi Jun 06 '14 at 09:32
  • If you want to paste `pages#fans` source I may be able to help further, although your work-around is good. – TuteC Jun 06 '14 at 14:21
  • Controller code is given below: `@page = Page.find_by_id(params[:id]) fan = @page.fans.where(:user_id => current_user.id).first if fan.blank? fan = @page.fans.create(:user_id => current_user.id) end @page.reload render :json => {:count => @page.fans.count}` – Abhi Jun 07 '14 at 07:51
  • Is there anyway to know the highest point earned by a user? (I need to subtract the points sometimes) – Abhi Jun 07 '14 at 11:48
  • Your rule will start working if you define the `@fan` instance variable, and it has to be the one found or the one just-created. I don't understand your last question, but points are just an SQL table, you can query it/inspect it at will. It's merit_scores_points. – TuteC Jun 07 '14 at 12:29
  • Let me elaborate - user earns points which are redeemable. So we want to display both "Lifetime" i.e., gross number & the net points (after redemption, if any) available as on a given date. So we rank users on lifetime, net number etc. I am wondering what is the best way to do this. Sorry if this question is beyond the scope of the gem... – Abhi Jun 07 '14 at 13:15

0 Answers0