我有一個'Create Account'視圖,我正在開始工作。 Backbone 1.1.2(typescript)前端,Rails 4.2 beta 1 Web服務後端。骨幹model.save()導致OPTIONS而不是POST
帳戶型號
export class Account extends Backbone.Model {
public urlRoot: string;
public validation:any;
constructor(attributes?: any, options?: any){
this.urlRoot = 'http://domain.fake/accounts';
this.validation = {
email: {
required: true,
pattern: 'email'
},
password: {
required: true,
minLength: 6
}
};
super(attributes, options);
}
}
創建的帳戶查看:上model.save()
export class CreateAccountView extends Backbone.View {
public template: string;
public events: any;
public model: accountModelImport.Account;
constructor(options?: Backbone.ViewOptions){
this.el = '#modal';
this.template = createAccountViewTemplate;
this.model = new accountModelImport.Account();
this.events = {
'click #create-account-submit' : 'create'
};
super(options);
}
public render(): CreateAccountView {
this.$el.html(_.template(this.template));
Backbone.Validation.bind(this);
this.$el.modal('show');
return this;
}
public create(){
var email:string = $('#create-account-email').val(), password:string = $('#create-account-password').val(), passconf:string = $('#create-account-password-confirmation').val();
this.model.set({email: email, password: password, password_confirmation: passconf});
this.model.save(null, {success: this.success, error: this.error});
}
public success(){
alert('Success');
}
public error(){
alert('error');
}
}
Rails的輸出從上面:
ActionController::RoutingError (No route matches [OPTIONS] "/accounts"):
我看到什麼傳遞的第一個參數.save()
很多問題,我每次它們都試過了同樣的結果:null, false, {}
我曾試圖用同樣的問題尋找一個問題,但都沒有能找到一個。我想在嘗試覆蓋.sync()
方法之前嘗試讓它在本地生效。
爲什麼.save()
試圖使用OPTIONS
而不是POST
?