I'm trying to create a rails app that allows users to submit information about their pets. I've come to a point where my knowledge is limited and I don't know enough about what/how this could be done so I'm hoping this will be relatively easy to answer.

At the moment I have a model called Pet, this model currently stores basic information like name, picture etc but it also holds more specific data like type, breed, date of birth etc. What I would like to be able to do is create a page that can match various records without having to be manually categorized if that makes sense so a users pet could be matched to other pets with the same breed, age etc.

I've read about nested models as I understand this information could be submitted to 2 models in one form but I am not sure whether this could be done directly in a separate controller which would only be visible to users with pets in these matched "groups" if that makes sense.

So in essence is it best practice to use 1 table to store all the information and just use a controller to match pets based on rows having the same values or would it be far simpler to have a form with a nested model and link 2 tables together?

The main feature needs to be matching without a user having to create a group or categorize pets so the second model would need to add id's to an array instead of just creating more and more rows.

1 Answer 1


I've used both one table and two tables. The nice thing about two tables is you can perform additional queries on the details of the pets table and, say pet_details - plus, it keeps the tables smaller and easier to manage.

With a nested model, you wouldn't necessarily create a new controller unless you wanted to directly manipulate the data through the web or an API for your nested model. The parent model Pet would handle all the manipulation of that data. TL;DR - it basically just keeps it more organized.

  • Would that mean you'd be storing pet_id in an array which would check the details before saving or just create a new row each time and do a find on the pet-details?
    – andybritton
    Nov 4, 2013 at 16:32
  • pet_details would belong_to pets and pets would have_many (or maybe has_one) pet_details. In my mind, you'd be storing pet_id on pet_details and run any validations there before saving. Does this answer your question?
    – CDub
    Nov 4, 2013 at 16:33
  • My pleasure. Let me know if you have additional questions. :)
    – CDub
    Nov 4, 2013 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.