Skip to content
JSON Dynamic Attributes with Rails
Branch: master
Clone or download
Latest commit d411149 Jan 9, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app Add solution Apr 12, 2019
bin Add solution Apr 12, 2019
config
db
lib
log Add solution Apr 12, 2019
public Add solution Apr 12, 2019
storage Add solution Apr 12, 2019
test Add solution Apr 12, 2019
tmp Add solution Apr 12, 2019
vendor
.gitignore Add solution Apr 12, 2019
.ruby-version Add solution Apr 12, 2019
Dockerfile Add solution Apr 12, 2019
Gemfile Add solution Apr 12, 2019
Gemfile.lock Add solution Apr 12, 2019
README.md Add solution Apr 12, 2019
Rakefile
config.ru Add solution Apr 12, 2019
docker-compose.yml Add solution Apr 12, 2019
package.json Add solution Apr 12, 2019

README.md

JSON Playground

This project was created as a proof of concept to work with dynamic fields that are stored in a JSON at the database level.

Use case

We have a Rails model, that can vary its fields in each record on the database, and because of this, we can't define hardcoded fields on the model (or concerns), and neither on the view level.

These dynamic fields are stored in a MySQL JSON field (or JSONB if using PostgreSQL), and we will validate them through another JSON field, that has the schema for it (using json-schema).

Our inspirations for this are the following resources: https://apidock.com/rails/ActiveRecord/Store/ClassMethods/store_accessor https://www.mariocarrion.com/2017/06/06/rails-5-json-array-fields.html https://nandovieira.com/using-postgresql-and-jsonb-with-ruby-on-rails http://jetrockets.pro/blog/rails-5-attributes-api-value-objects-and-jsonb https://blog.codeship.com/unleash-the-power-of-storing-json-in-postgres/

Commands

To run: docker-compose up

To restart the server: docker-compose exec web pumactl -F config/puma.rb -P tmp/puma.pid restart

To enter the container: docker-compose exec web bash

You can’t perform that action at this time.