Gioco游戏化宝石

时间:2014-03-20 17:54:47

标签: ruby-on-rails gem rake

我正在尝试使用Gamification Gioco Gem。我能够安装宝石。但是,当我尝试创建徽章时,我收到以下错误。随着我的深入,它似乎失败了

kind = Kind.find_or_create_by(name: 'hr') in the gioco.rake.rb 

以下是包含更多详细信息的完整日志

rake --trace gioco:add_badge[explorer,0,hr,true]
** Invoke gioco:add_badge (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute gioco:add_badge

rake aborted! 
undefined method `find_or_create_by' for #<Class:0x007ff9546bb778>
/Users/satya/gamification/gameclient/lib/tasks/gioco.rake:36:in `eval'
(eval):1:in `block (2 levels) in <top (required)>'
/Users/satya/gamification/gameclient/lib/tasks/gioco.rake:36:in `eval'
/Users/satya/gamification/gameclient/lib/tasks/gioco.rake:36:in `block (2 levels) in <top    (required)>'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/satya/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/application.rb:149:in `invoke_task'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/application.rb:106:in `each'
/Users/satya/.rvm/gems/ruby-1.9.2-p320/gems/rake-10.1.1/lib/rake/application.rb:106:in `block in top_level'

我正在使用rails 3.2.16。我想知道其他人是否在Rails 3.x环境中使用过它。

由于 萨蒂亚

1 个答案:

答案 0 :(得分:1)

Rails 3.2似乎不再支持find_or_create_by。

Rails 3.2的推荐方法是使用first_or_create,first_or_create!,first_or_initialize方法。所以改变代码

badge_string = "kind = Kind.find_or_create_by(name: '#{args.kind}').first_or_create! \n"

badge_string = "kind = Kind.where(name: '#{args.kind}').first_or_create! \n"

克服了这个问题。但是对于Gioco Gem用户的说明,其设置脚本似乎存在一些问题。不会创建点,徽章,级别的ID,您也会收到mass_assignment错误。不确定这个宝石是否得到了积极的支持。