Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically changing scores based on user activity. #299

Closed
hcyildirim opened this issue Jul 12, 2018 · 3 comments
Closed

Dynamically changing scores based on user activity. #299

hcyildirim opened this issue Jul 12, 2018 · 3 comments

Comments

@hcyildirim
Copy link

hcyildirim commented Jul 12, 2018

Hi,

I want to multiply scores based on user activity. And i can calculate if they are active or not from their point in a daily basis. (See: https://stackoverflow.com/questions/21092422/merit-gem-how-to-grab-a-users-points-for-a-single-day)

So when user gains a point from a rule i want to multiply this point from their activity status. Like:

score 10, to: :post_creator, on: 'comments#create', do |comment|
  if current_user.is_active?
     comment.score * 2
  end
end

How can i do that? And sorry for my bad english.
Thank you!

PS: I apologize for the other post, I do not know how I shared it twice.

@tute
Copy link
Member

tute commented Jul 13, 2018

Hi!

You could use a block to compute how many points should be awarded. See example from https://github.com/merit-gem/merit#examples-1. It will be something along the lines of:

ten_or_20 = lambda { | comment| comments.post_creator.is_active? ? 20 : 10 }
score ten_or_20, to: :post_creator, on: 'comments#create'

Does this solve your need? Thanks!

@hcyildirim
Copy link
Author

hcyildirim commented Jul 13, 2018

Hi,

Thanks, it solves my problem 😄 But i have another question, is merit works with api-only config? It doesn't work it i think.

@tute
Copy link
Member

tute commented Jul 15, 2018

Thanks, it solves my problem 😄

Yay!

i have another question, is merit works with api-only config? It doesn't work it i think.

It should work, but you might be encountering a known issue for which there's this open PR: #297. Feel free to contribute to the discussion, and even a fix!


Closing the issue as this is not a new bug in merit, but happy to continue the conversation.

@tute tute closed this as completed Jul 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants