Link Search Menu Expand Document

Consider adding these attributes for every new model

These are some common attributes that we've found to be useful to include in many models.

Your platform is effectively a CMS

The platform is effectively a specialized content management system. As you progress, your team will ask for different areas to be customizable through the interface, rather than code.

However, this causes a delay between the team needing customization having access to it.

Content areas have similar fields

Over time we noticed that some attributes frequently repeated:

  • name or title
  • published or enabled
  • start_date and end_date
  • slug (that should be automatically generated based on the name and have a history so that links don’t break)
  • icon
  • priority
  • Audit log entries

There would also be a few scopes, or saved queries:

  • published
  • prioritized
  • active

Which can be rolled into a reusable plugin

This functionality can be extracted into a reusable plugin making it trivial to add a decent base level of customization to all content.

In Supplybunny, for instance, I created a concern that has the scopes for the different fields. If the model has the field, I include the concern which creates the scope.

Building this mixin might be considered doing work in advance. However, the time required to build the mixin or to add the functionality once is similar, I think it’s justifiable.

Suggest an improvement to this page (