Merit Gem with Rails 3.2 ......没有任何显示

时间:2014-04-23 13:42:44

标签: ruby-on-rails-3.2 badge merit-gem

我想使用Merit gem,但......它什么也没显示。我已经阅读了这个Rails: Merit Gem Badge Not Registering or DisplayingRails 3.2 Merit Gem Badge not Working,但我不明白为什么它不起作用。

merit.rb

    # Use this hook to configure merit parameters
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'
end

# Create application badges (uses https://github.com/norman/ambry)
badge_id = 0
[{
  id: (badge_id = badge_id+1),
  name: 'Timide',
  description: '1 comment',
  level: 1
}, {
  id: (badge_id = badge_id+1),
  name: 'Bavard',
  description: '3 comments',
  level: 3
},{
  id: (badge_id = badge_id+1),
  name: 'Pipelette',
  description: '5 comments',
  level: 5
}].each do |attrs|
  Merit::Badge.create! attrs
end

badge_rules.rb

module Merit
  class BadgeRules
    include Merit::BadgeRulesMethods

    def initialize
      # If it creates user, grant badge
      # Should be "current_user" after registration for badge to be granted.
      # grant_on 'users#create', badge: 'just-registered', to: :itself

      # If it has 1 comment, grant commenter-1 badge
      grant_on 'comments#index', badge: 'Timide', level: 1 do |comment|
        comment.user.comments.count == 1
      end

comments_controller.rb

class CommentsController < ApplicationController
  before_filter :authenticate_user!, except: [:index, :show]

  # GET /comments
  # GET /comments.json
  def index
    @comments = Comment.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @comments }
    end
  end

我使用current_user.badges在我的视图中显示。

感谢您的帮助!

0 个答案:

没有答案