Routes.rb for supporting an Upsert

Hi all, Our team is increasingly hitting issues where we need to have an upsert operation in the API that will basically find_or_create on the parameters and not just an ID. The HTTP spec basically defines PUT as being compatible with the concept of an upsert.

I have started manually adding this with custom actions in many of our resources, but I wanted to raise this discussion here because I think a lot of other folks might be hitting this and silently working around it, and then many newbies are likely going to GraphQL or violating REST over needs like this. Baking it into the standard resources routes helper so that PUT to the index path does an upsert might be a great future default.

Do you have an idea how that would look in the routes api? If yes put it into a gem. Document it propely and if it gets milions of downloads migt eventually be added to rails core. Thats what i would do.

1 Like