How to avoid created_at and updated_at fields validation

Feature(s) impacted

Admin dashboard

Observed behavior

When I create a new record in the ForestAdmin dashboard, a validation on “created_at” and “updated_at” prevents me from saving the record.

Expected behavior

I should be able to leave the “created_at” and “updated_at” fields empty when creating a record in the dashboard. Then, the Rails app will automatically set the value to today’s time.

Context

  • Project name: TurkishFluent
  • Environment name: Production
  • Agent technology: Rails
  • Agent (forest package) name & version: …
  • Database type: Postgresql
  • Recent changes made on your end if any: installed ForestAdmin today, app hosted on Heroku

Hello @nico_lrx ,

You can edit the layout of the form to make this field “read-only”, so the validation will skip it.
1.
image
2.
image
3.
image

Kind regards

1 Like

Thank you for your answer. But when I create a new record I get the following error:

An error occurred when trying to create grammar: SequelizeDatabaseError: null value in column “created_at” of relation “grammars” violates not-null constraint

How to make Forest use the Rails system?
My previous setups with other rails apps don’t have this issue, I guess you changed the logic here.

Thanks.

Forest Admin is plugged directly on your database, if you want to do some custom logic when creating a record, you have to override the default behaviour: https://docs.forestadmin.com/documentation/reference-guide/routes/override-a-route#replacing-forest-admins-behavior

This is way more complicated than it used to be! Is it possible to use the rails gem and the previous logic instead?

Thanks.

Could you detail the previous logic ?
How is filled the “created_at” column in your other projects ?

If it is not completed by forestAdmin, it has to be completed from your code somewhere, to satisfy the “not null” contraint.