← Back to Upcase

Updating a model with attribute specific forms


(Nicolo) #1

Right now for my user model I have separate forms with separate actions to update different properties.

For example, a form to change username and a form to change password.

I have them go to different non-restful actions.

Should I just be using a single user update action with just different fields exposed in each form?


(Ben Orenstein) #2

Yep. I’d want to have one User#update action that could handle all User-related updates.


(Nicolo) #3

Thanks that is what I figured.

What about handling success and failure messages/actions differently for different forms? Do I do this via rendering different views?


(Ben Orenstein) #4

If you only need to change the text that’s displayed, you can just set the flash correctly in the controller.

The controller action can tell what the user is doing (changing password, updating their email) by the params they send, so you can choose the appropriate message if they’ve done something incorrectly.


(Nicolo) #5

What if the forms are being submitted via ajax and there are different dom manipulations happening after successfully submitting the form?

Then do I want to use different js view files?