Working with N:M Tables where one "side" is known
I've been having trouble googling my problem because it's hard to put into words.
I am working on an Animal Shelter Tracking program. I have two Models: Animals, which is self-explanatory, and Vitals, which holds the name of the vital sign (ie BP, Weight, etc). These tables are joined by animal_vital, which holds references to Vital and Animal, and also contains the vitals value and datetime it was taken.
I made views for animal_vitals, including an edit view and new view. Problem is that while I know the animal_id (the create/edit vitals links from the animal show view) I don't know how to add the animal_id to the url so that the animal_vitals can find it.
The link (which obviously won't work for you) to create a new vital is:
http://192.168.0.128:3050/animal_vitals/new
and I need it to be something like:
http://192.168.0.128:3050/animal_vitals/new/animal/2
My relations are fine. I have a working N:M working as a collection_check_boxes. I could just have the Animal be a dropdown in the animal_vital edit form, but Animal is always known I want to pull it in.
I am assuming that I need to change my routes.rb file to link to a page that includes the animal_id.
Is there a name for what I want to do so that I can google it?
Obviously actual solutions are welcome as well!
Posted Jul 9, 2025, 4:11 AM UTC