简体   繁体   中英

Rails update child from parent controller

So I have this simple situation:

User model has_one client I want to update client's attributes from user's update method (in controller) Should I accept nested attributes from client and update all as one, or should I update client independently (maybe call client's edit url from here) ?

Not sure what is the best way to do this.

Thanks in advance

If you just want to update the child entity, you should do that into the ChildsController .

You can update the child in the parent controller, but it is a violation of the REST principles. You are the ultimate authority in your code for what you can and cannot do, but following best practices will help you in the long run.

If you insist on following the dark side, I suggest you to just update the child without using the overcomplicated nested_attributes which use case is for a simultaneous update.

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