0

我收到消息错误 render :json=> {"status"=>"failed",:errors=>@user.errors.messages}.to_json

{
    "status": "failed",
    "errors": {
        "Email": [
            "has already been taken"
        ],
        ,
        "Username": [
            "has already been taken"
        ]
    }
}

但我想自定义错误:

{
        "status": "failed",
        "errors": {
            "error": [
                "Email has already been taken"
            ],
            ,
            "error": [
                "Username has already been taken"
            ]
        }
    }

请帮我解决这个问题。感谢您的支持。

4

1 回答 1

0

您可以my_custom_errors_messagesUser模型中实现方法。或者在模块中并将其包含在您的模型中。你将改变错误的地方有你想要的任何东西。

你也可以看看full_messages()它可能对你有帮助。

于 2013-10-30T09:36:29.163 回答