Rails:优异宝石徽章未注册或显示 [英] Rails: Merit Gem Badge Not Registering or Displaying

查看:83
本文介绍了Rails:优异宝石徽章未注册或显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了以下在DB中注册的徽章:

I set up the following badge which registered in DB:

merit.rb

Merit::Badge.create!({
id: 1,
name: 'Five Tasks'
custom_fields: { img_url: '/images/badge.gif' }
})

我设置了以下规则:

badge_rules.rb

grant_on 'tasks#create', :badge => 'Five Tasks', :temporary => true, :model_name => 'Task' do |task|
task.user_ids.count == 5
end

我想发生的事情是,当用户创建5个任务时,他们将获得一个徽章.

What I wanted to to happen is when the User created 5 tasks they would be issued a badge.

我在merit_actions和merit_activity_log条目中看到了数据库中的条目-但我认为在badges_sashes中没有看到任何内容,我认为这是发放徽章时它们将显示的位置-即使我已超过阈值-

I see entries in the DB in merit_actions and merit_activity_log entries -- but I do not see anything in the badges_sashes which I assume is where they would show when the badge has been issued -- even though I have surpassed the threshold --

我也不确定如何显示徽章---我正在使用:

Also I am uncertain how to display the badges --- I am using:

<%= current_user.badges %>

现在我所得到的只是方括号-我希望它返回的是徽章的图像---

Right now all I get is brackets -- what I want it to return is an image of the badge ---

非常感谢任何帮助.

推荐答案

您是否以散列形式访问徽章的custom_fields?您添加到custom_fields中的那些自定义属性(例如img_url,难度,颜色等)将无法以简单的点符号(即)访问. badge.img_url将不起作用.相反,您需要执行类似badge.custom_fields[:img_url]badge.custom_fields[:whatever_custom_attribute]的操作.希望修复会这么简单.

Are you accessing the badge's custom_fields as a hash? Those custom attributes that you add into custom_fields like img_url, difficulty, color, etc... won't be accessible in simple dot notation ie. badge.img_url won't work. Instead you need to do something like badge.custom_fields[:img_url] or badge.custom_fields[:whatever_custom_attribute]. Hopefully, the fix will be that simple.

这篇关于Rails:优异宝石徽章未注册或显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆