Rails 徽章/成就系统动态主列表
所以我使用以下方法: 如何在 RoR 中实现成就系统 在我的应用程序上实现徽章/成就系统。
到目前为止,这效果很好,但我希望有一个网站上当前存在的所有徽章的“主列表”。由于这个数量不断增加,我希望这个列表能够动态地自行填充,而不是我必须手动更新它。
这听起来很简单,但是由于成就系统的工作方式(各种类型的徽章都是 Achievement.rb 模型的子类......数据库中有许多相同徽章的实例)我不确定如何能够确定成就模型的所有子类。
此外,我希望每个徽章都有自己的显示页面(示例网址:http://www. mysite.com/achievements/badge1)
因此,在这个主列表中,徽章图像将如下所示:
<%= link_to "#{image_tag @achievement.photo}", achievement_path(@achievement) %>
但是,我再次不知道如何迭代成就模型的所有子类。
这有道理吗?我该怎么做呢?
谢谢,
So I am using the method in: How to implement an achievement system in RoR to implement a badges/achievement system on my app.
This has worked great thus far, but I am wanting to have a "master list" of all the badges that currently exist on the site. As this is continually increasing, I'd like it if this list could dynamically populate itself, instead of me having to update it by hand.
This sounds pretty easy, but because of how the achievements system works (the various types of badges are all subclasses of the Achievement.rb model...there are many instances of the same badges in the db) I am not sure of how to be able to determine all the subclasses of the Achievements model.
Additionally, I would like for each badge to have its own show page (example url: http://www.mysite.com/achievements/badge1)
So within this master list the badge images will look something like this:
<%= link_to "#{image_tag @achievement.photo}", achievement_path(@achievement) %>
However, yet again, I have no idea how to iterate through all the subclasses of the Achievement model.
Does this make sense? How should I go about doing this?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要迭代子类,您应该能够执行以下操作:
然后对于显示 URL,可能会创建一条类似“achievements/:badge”的路由,然后在控制器中执行以下操作:
To iterate through the subclasses, you should be able to do something like this:
And then for the show URLs, probably make a route like 'achievements/:badge' and, in your controller, do