有没有办法把 PointRules 类弄干一点?我试过了,但没有用:
%w(attr1 attr2 attr3).each do |attribute|
score 10, on: 'comments#create', do |comment|
comment.attribute.present?
end
end
它给了我这个错误:
private method `attribute' called for...
最终编辑:
下面提供的答案有效,而且您可以通过执行以下操作进一步干燥您的代码:
%w(attr1? attr2? attr3?).each do |attr|
score 5, on: ['comments#update', 'users#update'] do |item|
item(attr).call
end
score 10, on: ['comments#create', 'users#create'] do |item|
item(attr).call
end
score 15, on: ['comments#delete', 'users#delete'] do |item|
item(attr).call
end
end