我正在尝试使用 Backbone 1.1.2 和 Rails 4.2.beta1 创建一个用户帐户。
在骨干中,我打电话给:
public create(){
var email:string = $('#create-account-email').val(), password:string = $('#create-account-password').val(), passconf:string = $('#create-account-password-confirm').val();
this.model.set({email: email, password: password, password_confirmation: passconf});
this.model.save(null, {success: this.success, error: this.error});
}
create
它使用以下请求参数正确调用了我的 web 服务中的 rails方法:
{"email":"test@test.com","password":"123456","password_confirmation":"123456"}
它正在通过过滤器方法
def account_params
#breakpoint
params.require(:account).permit(:password, :password_confirmation, :email)
end
但是如果我在上述位置放置一个断点并检查params
我得到的对象:
{"email"=>"test@test.com",
"password"=>"123456",
"password_confirmation"=>"123456",
"controller"=>"accounts",
"action"=>"create",
"account"=>{"email"=>"test@test.com"},
"format"=>"json"}
乍一看,这对我来说是正确的。但是创建帐户失败,因为密码是nil
如果检查结果account_params
我只得到:
{"email" => "test@test.com")
为什么密码不包含在帐户参数对象中。我正在使用所有带有rails的默认支架代码和Backbone的默认配置。