Rails 4 / Devise / Merit gem : no target_obj found on Rule#applies? -


i'm trying implement badge system in rails app using merit gem.

i want give badge 100 first users of app. add code badge_rules.rb

grant_on 'registrations#create', badge: 'pioneer', model_name: 'user', to: :itself |user|    user.id < 101 end 

since i'm using devise (version 3.2.3), followed howto , overdrived registration controller :

class registrationscontroller < devise::registrationscontroller   def create     @user = build_resource # needed merit     super   end    def update     @user = resource # needed merit     super   end end 

but badge is'nt created. in log, can find these warnings :

[merit] no target_obj found on rule#applies?  [merit] no object found, maybe need '@registration' variable in 'registrations_controller'? 

i've put binding.pry in rule.rb file of gem, , it's clear : target_obj not user, it's nil.

the target_obj supposed set to: option in badges_rules.rb. tried :itself, :user, , nothing, don't solve problem.

of course tried add @registration = build_resource controller, took away warning didn't solve problem.

the behaviour of badge kind of wrong. it's suposed granted registered succesfully. working code 1 :

grant_on 'registrations#create', badge: 'inscription', model_name: 'user' 

but when had to: :itself it, @tutec advise me in question, don't work.

i don't understand behaviour of to: parameter.

the :to parameter can method name, called on target object (in case, @registration) should retrieve object badge. if using way, when put :user, merit internally running @registration.user find badge, not want.

:to can :itself, in case badges target object (@registration in case, which, if user, should work you).

i believe want badge whoever current_user, option's default (:action_user), shouldn't need define :to option.

that said, merit badge, condition has true, , can happen there's no user pass parameter rule. try without parameter:

grant_on 'registrations#create', badge: 'pioneer'   user.count < 101 end 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -