Topic: Understanding Many to Many
I am new to rails and am struggling to figure out just how to use the many-to-many options in the controller, database and view.
Lets say we have an product model and we have:
and the categories model:
So that in principle creates the relationship in the model. How do I go about adding the links to build this relationship? I am under the impression that you would add something like this to the products controller:
@categories = Category.find(params[:category_id])
And then in the view you could use something like product.categories.XXX.
But I am not sure if this is correct or where to go after the model. I have tried many tutorials and they either old or dont seem to work. Can anyone give me a simple tutorial so I can understand the basic relationship and I can then work from there?
I would be truly grateful.