1

我已经定义了奖励用户的行为和规则,这要归功于功绩宝石。

但是,它不起作用。执行奖励动作后,用户不拿任何积分。

这是我的代码:

首先,这是我的观点:

<div class="col-md-3 text-center">
<p class="dark-blue"><%= @user.points %></p>
<p class="grey-light">Points</p>
</div>

其次,这里是 point_rules 模型:

#Model/merit/point_rules.rb    
module Merit


    class PointRules include Merit::PointRulesMethods
    def initialize
      score 15, on: 'pages#create', to: [:user]
    end
  end
end

三、pagesController中的create方法:

    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

最后,优点.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

此外,Forest在 CLI 中告诉我,模型“Merit::ActivityLog”似乎不存在“关联”框格“。

如何解决?

提前谢谢你。

编辑:这里是可能的错误[优点]没有找到目标的堆栈跟踪:未初始化的常量页面。

/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)
4

1 回答 1

0

优点不适用于 Rails 4.2。

https://github.com/merit-gem/merit/issues/301

你必须使用

gem 'merit', '~>2.4'

该错误还NoMethodError on 'TrueClass#user'意味着true当它期望一个响应的对象时,某些东西正在返回#user

于 2018-08-08T23:40:30.337 回答