samedi 14 mars 2015

Why does devise me redirect me to /users instead of /users/edit when my account update fails?

The problem is like this:


If I use the default registration controller I get redirected:



  • /users/edit to root when user update succeeds

  • /users/edit to /users when update fails


Because the default controller update action looks like this:



if resource_updated
sign_in resource_name, resource, bypass: true
respond_with resource, location: after_update_path_for(resource)
else
clean_up_passwords resource
respond_with resource
end


after_update_path_for is set by default to root


If update fails I get the devise error messages and hasError div wrappers for the fields with error


In my registrations controller in the edit action I attribute values to a variable @myvar={2, 3}


This variable is used in the registrations_edit view


Whenever user update fails I get error no method .each for nil for my @myvar


How should I declare my view variables such that they are accessible even when update form fails?!


I have tried:


Forcing the controller to redirect to edit view no matter what:



if resource_updated
sign_in resource_name, resource, bypass: true
redirect_to edit_user_registration_path
else
clean_up_passwords resource
redirect_to edit_user_registration_path
end


This created problems because devise validations do not work anymore


Aucun commentaire:

Enregistrer un commentaire