1

I have installed Merit and have set up some points_rules. I'm successfully adding points to my 'user' when they create a comment but none of the others.

I am using Devise.

point_rules

module Merit
  class PointRules
    include Merit::PointRulesMethods

    def initialize
      score 10, :on => ['user#create', 'user#update'] do |user|
         user.preferred_drink.present?
       end
       score 20, on: 'comments#create', to: :user #is working!
       score 10, on: 'users#update', to: :user
       score 20, on: 'favorite_coffeeshops#create', to: :user  
    end
  end
end

user.rb

class User < ApplicationRecord
  has_merit
  has_many :favorite_coffeeshops      
  has_many :favorites, through: :favorite_coffeeshops, source: :coffeeshop

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable, :trackable 

favourite_coffeeshop.rb - joins table.

class FavoriteCoffeeshop < ApplicationRecord
  belongs_to :coffeeshop
  belongs_to :user

The user is able to add a new row in the favorite_coffeeshops table perfectly fine so that side is working ok.

From the console log it doesn't appear to be trying to write to the merit models.

Started PUT "/coffeeshops/new-shop-9c762d25-77e4-499a-b009-1ad150515dbb/favorite?type=favorite" for 127.0.0.1 at 2019-01-13 21:57:08 +0000
Processing by CoffeeshopsController#favorite as HTML
  Parameters: {"authenticity_token"=>"24cQlLc+UYT79P50rrBx9hlXckPj/3nCtVJ7fS6+UKO+UHTGDLBXlwLaVpVLf6Yj46VYyNiH0xdBzaUaU/LbHw==", "type"=>"favorite", "id"=>"new-shop-9c762d25-77e4-499a-b009-1ad150515dbb"}
  Admin Load (0.8ms)  SELECT  "admins".* FROM "admins" WHERE "admins"."id" = $1 ORDER BY "admins"."id" ASC LIMIT $2  [["id", 2], ["LIMIT", 1]]
  Coffeeshop Load (0.5ms)  SELECT  "coffeeshops".* FROM "coffeeshops" WHERE "coffeeshops"."slug" = $1 LIMIT $2  [["slug", "new-shop-9c762d25-77e4-499a-b009-1ad150515dbb"], ["LIMIT", 1]]
  User Load (0.9ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
   (0.3ms)  BEGIN
  FavoriteCoffeeshop Create (0.9ms)  INSERT INTO "favorite_coffeeshops" ("coffeeshop_id", "user_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"  [["coffeeshop_id", 22], ["user_id", 1], ["created_at", "2019-01-13 21:57:08.172483"], ["updated_at", "2019-01-13 21:57:08.172483"]]
   (0.6ms)  COMMIT
Redirected to http://localhost:3000/coffeeshops/new-shop-9c762d25-77e4-499a-b009-1ad150515dbb
Completed 302 Found in 26ms (ActiveRecord: 7.2ms)
Simon Cooper
  • 1,574
  • 4
  • 24
  • 53
  • Hi! Does `FavoriteCoffeeshop` `belong_to :user`? And did you see this wiki page? https://github.com/merit-gem/merit/wiki/How-to-grant-badges-on-user-using-Devise#on-devise-registration-without-confirmation for the `/users` endpoints? – TuteC Jan 15 '19 at 14:37
  • Hello. I've just added the model. Yes it does. – Simon Cooper Jan 15 '19 at 23:55
  • So does `favorite_coffeeshops#create` work now? And did you override the Devise controller as the wiki explains? – TuteC Jan 17 '19 at 00:10
  • Thanks @TuteC As the wiki only referenced Badges and not mention of points, I hadn't overridden the devise controller yet. Will this also allow points to work? – Simon Cooper Jan 17 '19 at 00:21
  • Ok after creating the new controller, i've got this working. `score 20, on: 'coffeeshops#favorite'` does the job. I am having issues with confirmed Devise users updating their profile. `score 10, on: 'users/confirmations#update', to: :user` hasn't done the job. – Simon Cooper Jan 17 '19 at 13:16
  • @TuteC i have the same issue with points rules. Could you take a look? https://stackoverflow.com/questions/74752382/rails-merit-gem-cannot-score-points-on-confirmations – Seto Dec 10 '22 at 11:13

1 Answers1

0

did you restart the server after rule settings? may be that is basic reason. I have faced same issu and solved like this way.

rails s