如何在rails应用程序中集成merit gem与不同型号名称的设计

时间:2014-08-30 22:15:48

标签: ruby-on-rails ruby ruby-on-rails-4 devise

我创建了一个rails应用程序,在我的rails应用程序中,我有两个使用设计gem,Student和Teacher创建的模型。现在我想为学生添加优点宝石,为他们分配徽章和积分。     我已经尝试了很多并按照[1]中给出的每一步:https://github.com/tute/merit并且还搜索了stackoverflow上给出的问题,但它并没有那么有用。

在我的控制器中,学生/ registrations_controller.rb

class Students::RegistrationsController <  Devise::RegistrationsController

    def create 
       @student = build_resource
       super
    end
end

在我的模型中,我在类Student

中添加了has_merit

在我的config / initializer / merit.rb

Merit.setup do |config|
   config.checks_on_each_request = true
   config.orm = :active_record
   config.user_model_name = 'Student'
end

badge_id = 0
[{
  id: (badge_id = badge_id+1),
  name: 'just-registered'
}, {
  id: (badge_id = badge_id+1),
  name: 'best-unicorn',
  custom_fields: { category: 'fantasy' }
}].each do |attrs|
  Merit::Badge.create! attrs
end

我的models / merit / badges_rule.rb具有以下代码行     grant_on'students / registrations #create',badge:'best-unicorn',model_name:'Student'

我创建了所有迁移和数据库表。 每次注册时我的sash_id设置为nil。我没有在学生的表格中找到sash_id。

1 个答案:

答案 0 :(得分:1)

如果你只写class RegistrationsController < Devise::RegistrationsController怎么办?

然后在你的badges_rule.rb grant_on 'registrations#create', badge: 'best-unicorn', to: :user