Question about models

Hey all, I have another question. I am currently designing a database for a website that allows users to sign up for hiking trips that a club at the university i'm at sponsors. Currently, I have Users/Trips/Cars/Carpools/CarpoolUsers/TripUsers. I have one problem though, I know how to create the model for Carpools/CarpoolUsers/TripUsers but since each of those tables within the database belong to either Users/Trips/Cars or a combination of those 3, they don't exactly need their own Controller or View for that matter. But, I don't know the proper rails convention for models that don't necessarily need a View or a Controller.

Hopefully that makes sense, I would love to get some help with this, thanks for reading!

2 thoughts on “Question about models”

  1. Unsure about the question. The convention is just to make the model without a corresponding controller or view.

    What are you particularly struggling against or doesn’t make sense to you yet?

  2. You don’t need any of the ‘VC’ from the scaffold generator. If you’re only looking for the migration and model file to start with

    rails g model TripUser trip_id:int user_id:int

    This will generate for you a model file, and a migration. It might get you a spec and factory file as well depending on your gems.

    There are a lot of reasons for models that don’t need views or controllers, it’s nothing to worry about.

    Also depending on what you’re trying to do, using HABTM might be even easier to use, since you don’t need a join model. If you’re not sure if you’ll need the flexibility of a join model, start with HABTM, it isn’t as flexible as HMT but refactoring in to HMT is pretty straight forward.


Leave a Comment