阅读背景:

Rails 5 - 无法使用as_json渲染关联

来源:互联网 

Explanation:
I have 2 models, User and Interests, associated by a has_and_belongs_to_many. When a User is created I need to create all the interests and make the correct associations. Its an API, so I use as_json to render the response, but for some reason when I delete previous associations (self.interests.delete_all) and create new ones inside associate_interests method they don't render to the response. If I remove the "self.interests.delete_all", it renders all the associated interests. I have 2 models, User and Interest




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: