Rails save method as you are using it will only save the selected id
key from category into the category_id field in your Product table but
will not save the category name into the “category” field.
So validates_presence_of :category in your Product model will give an
error because there is no data saved into the category field.
You can check this by looking in your database table and you will see
no data in the category field but the id field has the category id.
Try your code without the validates_presence_of :category.
I am very new to Rails - a few weeks!!! so I dont have the complete
answer - I hope this piece is helpful.
I also have the same problem and must find a way of populating my
category name field as well as the id field!!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.