Comments (6)
If we store badges in a DB table, and we deploy an app without synchronizing the badges data with the server's, it will raise an exception for badge not found, or methods called from merit
on nil
. Having the app rely on DB entries makes it weak and error prone. Also, if you are developing an app with more people, you all have to have the exact same badges
table, which is awckward.
Also, badges tend to be a rather stable piece of information, and, as the app's stability depend on it, makes much more sense to have that data in the code, and sourced controlled. If you change merit rules badges you are changing code, and so you change badges data there also. Suppose you add a new rule for a new badge, you'd need to add a table entry for that badge in all your app instances.
ambry is a small library which provides a nice interface to the store of this kind of objects which are not code but neither harmless data. Technically it wouldn't be hard to have them as plain Ruby Objects, in an Array or Hash, but I needed ambry's validations and liked filters syntax.
I'm open to better/simpler ways of solving this. Thanks for your feedback!
from merit.
Added notes to merit wiki/FAQ: https://github.com/tute/merit/wiki
from merit.
Thank you for your answer. You're right with data synchronization. But Ambry still feels akward to me. There is no migration file and I cannot change Badge model.
I can see only one possibility of synchronization: your migrations are exactly meant for this.
from merit.
Oh, maybe it's not explained easily in the README, but badges are described in your app's config/initializers/merit.rb
, so syncronyzation is automatic. Badges are "created" when app boots up, reading them from that application initializer. In fact I don't know how to run DB commands (creating entries correctly) from migrations, but I do know that this solves the syncronization problem.
See my example (if you think README could be better please tell me, or send a pull request! :-) ):
$ cat config/initializers/merit.rb
# Use this hook to configure merit parameters
Merit.setup do |config|
# Check rules on each request or in background
# config.checks_on_each_request = true
# Define ORM. Could be :active_record (default), :mongo_mapper and :mongoid
# config.orm = :active_record
end
# Create application badges (uses https://github.com/norman/ambry)
Badge.create(
id: 1,
name: "just-registered",
description: "Welcome to my site!"
)
# [...]
from merit.
In fact it's not described in the README, can't believe it. Should be the fourth installation step. Thanks for noticing.
from merit.
I know this is a closed issue, but it is the first search result for anything like "Using a database for badges for Merit gem." If you absolutely, positively must use a DB for configuring badges, just get your badge data from the DB, then use ActiveRecord's as_json method to get it as an array of hashes. The just feed that hash into the .each do |attrs| Merit::Badge.create! attrs
that is generated by the install script. Easy.
from merit.
Related Issues (20)
- Add/Subtract points: NO Method error HOT 8
- undefined method 'create' for Merit:Action:Class HOT 12
- Use DeviseInvitable with Merit HOT 2
- Display flash messages to notify users when they obtain badges/points HOT 9
- Adding points doesn't work the first time HOT 1
- Display a specific badge and the users who obtained it HOT 2
- Merit 4.0 causing Heroku deployment errors HOT 4
- Typo in active_record/merit_generator task
- Deprecation warning: Expected string default value for '--orm'; got false (boolean). HOT 3
- Granting badges with Devise Registrations#update not working HOT 11
- rails g merit:install don't generating migrations on Rails6 HOT 18
- can't write unknown attribute `sash_id` when calling points method on user HOT 3
- subtract_points is not working HOT 3
- Missing index on merit_actions table for processed HOT 2
- Error on create merit_actions migration file HOT 2
- Score on namespaced/controller#action, can not trigger Merit::Action HOT 6
- Error every time code changes HOT 7
- do not support grape? HOT 1
- Devise & Sign-in then trigger grant_on HOT 12
- On destroy, Integer returned instead of object HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from merit.