Git Product home page Git Product logo

Comments (6)

tute avatar tute commented on August 21, 2024

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.

tute avatar tute commented on August 21, 2024

Added notes to merit wiki/FAQ: https://github.com/tute/merit/wiki

from merit.

SpOOnman avatar SpOOnman commented on August 21, 2024

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.

tute avatar tute commented on August 21, 2024

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.

tute avatar tute commented on August 21, 2024

In fact it's not described in the README, can't believe it. Should be the fourth installation step. Thanks for noticing.

from merit.

crcapps avatar crcapps commented on August 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.