2

我将功绩宝石用于徽章/积分,它在应用程序中没有任何作用。在控制台中它可以工作,但在应用程序中它没有。

在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 :mongo_mapper and :mongoid
  config.orm = :active_record

  #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.create!({
 :id => 1,
 :name => 'just-registered'
})

Badge.create!({
  :id => 2,
  :name => 'voter',
})

Badge.create!({
  :id => 3,
  :name => 'liker-on-steroids'
})

在 point_rules.rb 中:

module Merit


class PointRules
include Merit::PointRulesMethods

def initialize
  # score 10, :on => 'users#update' do
  #   user.name.present?
  # end
  #
  # score 15, :on => 'reviews#create', :to => [:reviewer, :reviewed]
  #
  # score 20, :on => [
  #   'comments#create',
  #   'photos#create'
  # ]

  score 10, :on => 'users#update' do |user|
    user.nickname.present?
  end

  score 20, :on => 'pictures#create', :to => :user

  score 5, :on => 'pictures#vote_up', :to => :user do |picture|
    picture.vote_up
  end

  score 5, :on => 'pictures#vote_against', :to => user do |picture|
    picture.vote_against
  end
end
end
end

让我们把图片上的20分#create:

def create
    @picture = Picture.new(params[:picture])
    @picture.user_id = current_user.id
    @picture.fame = false
    if @picture.save
      redirect_to root_path, notice: "Picture saved."
    else
      redirect_to root_path, error: "Could not save picture."
    end
  end

路线:

resources :pictures do
    member do
      post :vote_up
      post :vote_against
      post :unvote
    end
  end

但不仅如此。没有任何效果,它实际上没有响应 - 无论我做什么,它都不会给用户积分或徽章。

我正在使用 OmniAuth (facebook) 注册用户

4

1 回答 1

-2

看看这个,我想这可以给你一个方法!

祝你好运!

于 2013-03-04T13:09:42.537 回答