简体   繁体   中英

Rails 3: has_many through controller action

I've got a Rails 3 app setup that I use for driving an API, with a has_many through association working. I know that to setup the association I should use device.favourites.create(object) and that works fine when I run it either within the web app, or on the console but I don't know how I should use it for the controller action for a json request. Should I POST to the join model ( Favourites ) or one of the models at the end ( Device / Store )? If I POST to the one of the models at either end, should I calling the .create method with controller create method?

I ended up just using the join model to accept a params hash containing both the variables it links against. It was the cleanest way to do it and it seems to work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM