What you are doing wrong is trying to combine two different actions: new and edit.
params is a hash of parameters that you receive from the client.
When creating a new object, params[:id] remains empty, since the id attribute of the newly created object is the responsibility of the server, not the client.
When you edit an existing object, params[:id] not empty, since the object already exists in the database and has an identifier. The meaning of params[:id] here: "Please edit the object with id param [: id] using these attributes."
After explaining this, when you create the new object, this line:
@category = Category.find(params[:id])
Failure with params[:id] empty.
source share