jquery - Rails Devise ajax registration json error handling -
as newbie in rails, stumbled upon problem can't seem figure out how solve.
so i've been making ajax registration , works wanted, except 1 thing. when there errors in registration handle them so:
error: function(xhr) { var errors = jquery.parsejson(xhr.responsetext).errors; (messages in errors) { (message in errors[messages]) { popup(message + " " + errors[messages][message], 'error'); } } }
the output example this: (this want change)
- email has been taken - date_of_birth can't blank
if don't use ajax output becomes this: (this want get)
- email has been taken - date of birth can't blank
my xhr.responsetext
json data looks this:
{ "errors": { "email": { 0: "has been taken" }, "date_of_birth": { 0: "can't blank" } } }
obviously i've been using key showing output, think of alternative.
my questions is: how make error output ajax show same result devise outputs them default?
update: overridden devise registrations controller:
class user::registrationscontroller < devise::registrationscontroller respond_to :json private def sign_up_params params.require(:user).permit(:email, :password, :gender, :looking, :date_of_birth) end def account_update_params params.require(:user).permit(:username, :email, :password, :current_password, :gender, :looking, :date_of_birth, :description) end end
Comments
Post a Comment