我是 emberjs (1.0.0-RC1) 的新手,我在 Rails 上使用它。我想在不使用 ember 模型的情况下提交会话表单。我觉得这更好,因为我的 rails 应用程序中没有真正的会话模型。目前有效的方法如下:
#login_controller.js.coffee
SkillUp.LoginController = Ember.ObjectController.extend
# Just a title to pass to the template, for fun
title: "Login Controller"
submit: (controller) ->
model = @get 'model'
model.get('transaction').commit()
#session.js.coffee
SkillUp.Session = DS.Model.extend
email: DS.attr 'string'
password: DS.attr 'string'
#login_route.js.coffee
SkillUp.LoginRoute = Ember.Route.extend
setupController: (controller) ->
controller.set 'title', "Login"
controller.set 'content', SkillUp.Session.createRecord()
<!-- login.handlebars -->
<h2>template: {{title}}</h2>
<form>
{{#with controller}}
email: {{view Ember.TextField valueBinding="email"}}
password: {{view Ember.TextField valueBinding="password" type="password"}}
<button {{action submit}}>Submit</button>
{{/with}}
</form>
正如我所说,我的目标是删除 session.js.coffee,因为它不存在 rails 模型。
帮助将不胜感激谢谢