我想创建一个用户帐户使用骨干1.1.2和Rails 4.2.beta1。Rails的account_params缺少骨干参数`.save()`
骨干,我呼吁:
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服务与下面的请求参数:
{"email":"[email protected]","password":"123456","password_confirmation":"123456"}
它是通过过滤方法去
def account_params
#breakpoint
params.require(:account).permit(:password, :password_confirmation, :email)
end
但如果我在上面没有放置断点编辑点和检查params
对象,我得到:
{"email"=>"[email protected]",
"password"=>"123456",
"password_confirmation"=>"123456",
"controller"=>"accounts",
"action"=>"create",
"account"=>{"email"=>"[email protected]"},
"format"=>"json"}
这对我来说看起来是正确的第一眼。
{"email" => "[email protected]")
为什么没有被列入考虑的参数对象的密码:但是,因为密码是nil
如果检查的account_params
结果我只得到账号创建失败。我正在使用所有带有rails的默认sacaffolded代码和Backbone的默认配置。
你可以发表你的表格吗? – Mandeep 2014-10-05 18:01:37
@Mandeep我为你编辑了上面的代码。它是一种形式,但是我正在使用'$()。val()'将它从表单中读出来,所以我将这些代码包含在内。 – SnareChops 2014-10-05 18:04:27
啊好的,你如何将这些参数发送到服务器?看着你的参数哈希他们似乎并没有正确嵌套 – Mandeep 2014-10-05 18:14:12