I am a rails beginner and I am having trouble understanding how to use the MVC for a many-many relationship. All of the resources I can find, don't explain how to use the has_many through association in a MVC context, they always use the console to create the objects.
Overview of what I am trying to do:
Library system where there are many users and many books, each user can checkout multiple books, and a book can be checked out by many users.
Here is what I have:
- Created a
Booksscaffold for CRUD operations - Created a
Usersmodel using devise - Created a 3rd model
Checkoutsto linkBooksandUsersin ahas_many through:association
What I need help with:
Should I also create a
Checkoutsscaffold for CRUD operations? because I need to create/update/destroy links between books/users when they checkout/return books in a MVC context? How would this work as the only experience I have with controller is the one created through theBooksscaffold, which references books as@books, would theCheckoutscontroller be able to identify whichBookandUserobject I am attempting to create a link for or how does this work???????If
Checkoutsdoes not need to be a scaffold for CRUD operations, how do I create functions in the controller to reference abookanduserobject and insert them into the database? As well as make it a usable route for the view?
PLEASE DO NOT GIVE ME RAW LINKS WITHOUT EXPLANATION, I have read a bunch of rails documentation and watched hundreds of "tutorials" but none of them explain it in a practical MVC usage.