Rails 4: Merit Gem: DRYing up the PointRules code? -
is there way dry pointrules class bit? tried didn't work:
%w(attr1 attr2 attr3).each |attribute| score 10, on: 'comments#create', |comment| comment.attribute.present? end end
it gave me error:
private method `attribute' called for...
final edit:
the answer provided below works plus can dry code further doing this:
%w(attr1? attr2? attr3?).each |attr| score 5, on: ['comments#update', 'users#update'] |item| item(attr).call end score 10, on: ['comments#create', 'users#create'] |item| item(attr).call end score 15, on: ['comments#delete', 'users#delete'] |item| item(attr).call end end
sorry wait :(
here solution might you
%w(attr1? attr2? attr3?).each |attr| score 10, on: 'comments#create', |comment| comment.method(attr).call end end
active record adds boolean methods columns, why used question mark on columns.
please let me know if have questions.
Comments
Post a Comment