Backbone.js 422错误,设计/主干
我正在尝试设置一个Rails应用程序,该应用程序使用主干网和Desive进行注册 Chrome控制台中错误回调的响应文本显示Backbone.js 422错误,设计/主干,backbone.js,devise,Backbone.js,Devise,我正在尝试设置一个Rails应用程序,该应用程序使用主干网和Desive进行注册 Chrome控制台中错误回调的响应文本显示 responseText: "{"errors":{"email":["can't be blank"],"password":["can't be blank"]}}" 但是,服务器中的日志显示不可处理的实体 Parameters: {"email"=>"pp@rr.com", "password"=>"[FILTERED]", "password_co
responseText: "{"errors":{"email":["can't be blank"],"password":["can't be blank"]}}"
但是,服务器中的日志显示不可处理的实体
Parameters: {"email"=>"pp@rr.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "registration"=>{"email"=>"pp@rr.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}
(0.1ms) begin transaction
(0.1ms) rollback transaction
Completed 422 Unprocessable Entity in 4ms (Views: 0.3ms | ActiveRecord: 0.1ms)
我有一个主干用户模型,用于设置保存的url
UserRegistration = Backbone.Model.extend({
url: '/users.json',
paramRoot: 'user',
defaults: {
"email": "",
"password": "",
"password_confirmation": ""
}
});
在关联视图中,我从注册表中获取属性,在模型中设置它们,然后保存模型
var email = $('#email').val();
var password_confirmation = $('#password_confirmation').val();
var password = $('#password').val();
this.model.set({email : email, password_confirmation: password_confirmation, password: password})
this.model.save(this.model.attributes, {
success: function(userSession, response) {
console.log("success");
console.log(userSession);
console.log(response);
console.log(this.model.url);
},
error: function(userSession, response) {
console.log("error");
console.log(userSession);
console.log(response);
}
});
}
在设置了模型属性(保存之前)之后,我做了一个console.log(this.model.attributes),并对它们进行了设置
Object {email: "oo@gmail.com", password: "snowy", password_confirmation: "snowy"}
我的用户模型如下所示
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
class用户
有人能提些建议吗
最近的Desive版本只对html做出响应时出现了一些问题,因此我安装了Desive 2.1.2,使其能够用json做出响应,从而使其与主干网兼容。这不是这里的问题。paramRoot不是主干核心的一部分。为了解决这个问题,我必须包含主干Rails gem中的同步库,以使用户成为param root的一部分
url: '/users.json',
paramRoot: 'user',
您正在使用rails gem上的@muistooshort主干。
paramRoot:“用户”
在与服务器交谈时,应该将所有数据放在“用户”
命名空间中,不是吗?但是请注意,params
中的所有内容都是顶级的…@muistooshort我正在使用的与设计相关的代码(包括paramRoot)的一部分是从可能使用主干轨道的人那里获取的。我认为paramRoot来自于这个gem,而不是主干核心的一部分。这可能就是问题所在。你知道我如何在不使用宝石的情况下添加类似于paramRoot的东西吗?