Rails update attributes not updating

06-Mar-2020 11:43 by 2 Comments

Rails update attributes not updating

The below method will update existing custom attributes or create new ones where current ones do not exist.

If you get this error, let's assume you want to update custom attributes and go ahead and do that.Otherwise, let's update the standard attribute. In this article, you learned how to track attribute changes in Rails 5.We can also add new attributes to the User Model, called custom attributes.As we have been doing with previous actions, we can create a method to the user_file to do this.This can be very powerful in that multiple objects with complex associations can be updated simultaneously with a single line of code.

However, Rails makes certain assumptions about the structure of the params hash that gets passed to a given object when trying to update nested attributes.There is no need to enable partial update in Rails 5. In my experience using Rails to build web apps, I’ve come to realize that the framework has a very powerful flow of convention and patterns that you swim against at your own peril.In fact, adding an id to the team_attributes hash that is not the id of the currently associated team will raise an error (something along the lines of “team with ID= could not be found for player with ID=”).This seems counterintuitive to me, as I would want to be able to pass along all my associated data in the team_attributes hash (including the id of the team that I want updated) and have ANAF do both the association and the attribute assignment.The end goal of all this is to pass a params object into an assign_attributes or update_attributes call in the controller to update not only the primary object, but also all related objects.