【发布时间】:2014-10-05 16:43:46
【问题描述】:
我正在着手处理“创建帐户”视图。 Backbone 1.1.2 (typescript) 前端,Rails 4.2 beta 1 Web 服务后端。
帐户模型
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);
}
}
创建帐户视图:
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 从上方输出model.save():
ActionController::RoutingError (No route matches [OPTIONS] "/accounts"):
我已经看到很多关于将什么作为第一个参数传递给 .save() 的问题,并且我每次都尝试过它们,结果都是相同的:null, false, {}
我已尝试搜索具有相同问题的问题,但无法找到。在我走上覆盖.sync() 方法的道路之前,我想尝试让它在本地工作。
为什么.save() 尝试使用OPTIONS 而不是POST?
【问题讨论】:
标签: ruby-on-rails backbone.js typescript backbone-model