I'm trying to set a badge_rule for a first create action named "Selection" (product selection by members).
The rule :
grant_on 'member/selections#create', badge: 'FirstSelection', to: :member do |selection|
selection.member.selections.count == 1
end
The controller "Selections" is in the folder "member" : controllers/member/selections_controller.rb
At the #create action, here's my error report :
Merit::Action Load (0.4ms) SELECT "merit_actions".* FROM "merit_actions" WHERE "merit_actions"."processed" = $1 [["processed", "f"]] (0.2ms) BEGIN SQL (0.4ms) UPDATE "merit_actions" SET "processed" = $1, "updated_at" = $2 WHERE "merit_actions"."id" = $3 [["processed", "t"], ["updated_at", "2018-05-07 09:35:24.776028"], ["id", 30]] (0.5ms) COMMIT [merit] no target found: uninitialized constant Member::Selection. /Users/youguild/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find' Completed 500 Internal Server Error in 211ms (Views: 2.8ms | ActiveRecord: 134.4ms)
NoMethodError (undefined method `member' for true:TrueClass):
app/models/merit/badge_rules.rb:53:in `block in initialize'
Why is the error happening and how can I resolve it?
This problem was solved by :
It's translating the controller name into the model name, but the controller is namespaced with Member
. Try adding the option model_name: "Selection"
to your grant_on
line.