Merit不会使用设计在DB中创建徽章

时间:2014-04-26 10:58:29

标签: ruby-on-rails ruby-on-rails-4 merit-gem

我有一个使用devise,rails 4和ruby 2.1.0的rails应用程序。设计使用user模型和config.scoped_views = true。我已经按照this wiki使用设计来设置优点。当用户注册徽章时没有添加到数据库中 - 如果我使用createcurrent_user.add_badge('1')操作中手动添加徽章,它确实有效,我可以在视图中显示徽章。我已经在下面发布了相关代码,如果有人能告诉我我错过了什么? Merit提供了很棒的功能,我真的很想让它工作 - 谢谢!

app/controllers/users/registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController
  def create
    @user = build_resource # Needed for Merit
    super
  end

  def update
    @user = resource # Needed for Merit
    super
  end
end

app/models/user.rb

class User < ActiveRecord::Base
  has_merit

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end

config/routes.rb

Rails.application.routes.draw do
  devise_for :users, controllers: { registrations: 'users/registrations' }
end

app/models/merit/badge_rules.rb

module Merit
  class BadgeRules
    include Merit::BadgeRulesMethods

    def initialize
      grant_on 'registrations#create', badge: 'just-registered', model_name: 'User'
    end
  end
end

config/initializers/merit.rb

Merit.setup do |config|
  config.checks_on_each_request = true
end

Badge.create!(
  id: 1,
  name: 'just-registered'
)

0 个答案:

没有答案