在 #create 操作中找不到目标

Merit no target found on a #create action

我正在尝试为名为 "Selection"(成员选择产品)的第一个创建操作设置 badge_rule。

规则:

app/models/merit/badge_rules.rb

grant_on 'member/selections#create',  badge: 'FirstSelection', to: :member do |selection|
   selection.member.selections.count == 1
end

控制器 "Selections" 在文件夹 "member" 中:controllers/member/selections_controller.rb

在#create 操作中,这是我的错误报告:

Merit::Action Load (0.4ms) SELECT "merit_actions".* FROM "merit_actions" WHERE "merit_actions"."processed" = [["processed", "f"]] (0.2ms) BEGIN SQL (0.4ms) UPDATE "merit_actions" SET "processed" = , "updated_at" = WHERE "merit_actions"."id" = [["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'

为什么会出现错误,我该如何解决?

编辑

此问题已解决:

  1. 在 grant_on 上添加模型名称: model_name: 'Selection' (在这种情况下)
  2. 检查实例变量是否带“@”。是 'selection = Selection.new(selection_params) ' => ' @selection = Selection.new(selection_params) '.

它正在将控制器名称转换为模型名称,但控制器的命名空间为 Member。尝试将选项 model_name: "Selection" 添加到 grant_on 行。