Accueil À propos Contact / Devis
Back to all posts
October 2023 rails

String not matched with Rails and jsonb data

Today is a short post about an issue that didn’t have a very straight answer after some Googling. I hope this can help someone having the same issue :-)

I ran into the String not matched error when I was using StrongParameters and trying to mass assign attributes of a model from a controller, some classic Rails work, we could say.

In my case, the error was due to setting the default value of the jsonb column I’m using for storage as "{}". Instead, I should have use {}

There is more detail on this issue available here.

The fix is quite simple:

  1. create a new migration to change the default value of the column:
change_column :your_model, :your_column, :jsonb, default: {}
  1. update your existing data:
YourModel.where(your_column: "{}").update(your_column: {})