Is There A RESTful Way To Configure Routes For Habtm?
In Rails you can use nested routes to create RESTful routes for has_one and has_many relationships. Examples can be found on the Rails Guides
I'd like to ask if there is a good way to configure RESTful routes for habtm relationships? For example if I have a relationship A-habtm-B, my idea is to configure nested routes for A has_many B, and nested routes for B has_many A. Would that work? Or is there a better way?
Since HABTM is a two way
has_many association, your approach is correct and nested resources on both sides will work just fine. Other than that, I would reconsider using a
has_many :through association instead of HABTM, since it's more versatile.
- → Trigger a click with jQuery using link_to of rails 4
- → Adding html data attribute to simple_forms input
- → How to remove parameters from the root URL if it does I18n
- → passing parameters to rails back end from an ajax call
- → Blocking ?page= in robots.txt
- → react js and rails Updating state on a component with active record relationship
- → State not passed into prop
- → Cannot read property 'modalIsOpen' of undefined
- → Objects not valid issue
- → How to map API params to model
- → Consuming webhooks shopify-api
- → How to add ScriptTag on shopify_api gem?