Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
You often want to track what user's are doing throughout your app. There are some gems that help you do this. For example, activerecord_activity_tracker or public_activity. However, gems like these sometimes utilize polymorphic relationships, which don't scale well, or they're very opinionated about the setup. When your requirements differ from the default setup, it can become cumbersome to implement.
We use the nifty JSONb Accessor gem to create accessor methods for the relevant fields. You can also use anything in ActiveModel including validations. This takes advantage of ActiveRecord's single table inheritance features where the model name, in this case update_post is stored in the type field in TrackedEvent.
Related posts
- Is JSONB + Postgres still a viable way of storing varying attributes?
- Is there a way you can create a base model and your client may add attributes as needed?
- N1Loader is alive as ever Enhance your GraphQL API by getting rid of N+1 issues
- historical data and "point in time" data modeling techniques, advice.
- How to use store_accessor for nested JSON in rails