I have defined actions and rules to reward users thanks to merit gem.
However, It does not work. After having execute the rewarded actions , the user does not take any points.
Here is my code:
first , here is my view:
<div class="col-md-3 text-center">
<p class="dark-blue"><%= @user.points %></p>
<p class="grey-light">Points</p>
</div>
Secondly, here is the point_rules model:
#Model/merit/point_rules.rb
module Merit
class PointRules include Merit::PointRulesMethods
def initialize
score 15, on: 'pages#create', to: [:user]
end
end
end
Thirdly, the method create in the pages Controller:
def create
@comment = Comment.new
@comment.title = params[:title]
@comment.content = params[:content]
@comment.created_at = params[:created_at]
@comment.score = 0
@comment.author = User.find(session[:user_id]).user_name
@comment.user = User.find(session[:user_id])
@comment.save
redirect_to "/feed"
end
Finally,the merit.rb:
#config/initializers/merit.rb
Merit.setup do |config|
# Check rules on each request or in background
config.checks_on_each_request = true
# Define ORM. Could be :active_record (default) and :mongoid
config.orm = :active_record
# Add application observers to get notifications when reputation changes.
# config.add_observer 'MyObserverClassName'
# Define :user_model_name. This model will be used to grand badge if no
# `:to` option is given. Default is 'User'.
config.user_model_name = 'User'
# Define :current_user_method. Similar to previous option. It will be used
# to retrieve :user_model_name object if no `:to` option is given. Default
# is "current_#{user_model_name.downcase}".
config.current_user_method = 'current_user'
# Add application observers to get notifications when reputation changes.
# config.add_observer 'MyObserverClassName'
end
Furthermore, Forest tells my in the CLI that "The association "sash" does not seem to exist for model "Merit::ActivityLog".
How to solve that?
thanks you in advance.
EDIT : here are the stack traces of the possible error[merit] no target found: uninitialized constant Page.
/Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] no target found: uninitialized constant Page. /Users/charbe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/merit-3.0.1/lib/merit/base_target_finder.rb:13:in `find'
[merit] NoMethodError on `TrueClass#user` (called from Merit::TargetFinder#other_target)
[merit] NoMethodError on `TrueClass#user` (called from Merit::TargetFinder#other_target)
Merit doesn't work with Rails 4.2.
https://github.com/merit-gem/merit/issues/301
You have to use
gem 'merit', '~>2.4'
Also the error NoMethodError on 'TrueClass#user'
means that something is returning true
when it is expecting an object that responds to #user
.