Suppose I have a client side app that sends out requests to a rails back end. One of those requests would to create a new object, say a Post. In this case the client side app sends in a json request containing a post title and the post content.
But now suppose that the object needs to have an id as well, which the client side app doesn’t provide. Is there a way for rails to automatically increment the previously created post’s id and set the newly created objects id to this value?
Would I put this into the create method of PostsController? Or does this sort of logic belong in the model file?
Typically this is done at the database level. The tables rails generated for you will by default have an auto incrementing id column