-
-
Save JoshReedSchramm/5617045 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How you could do what you want in Ember | |
App.Router.map(function(){ | |
this.resource("userSession", function(){ | |
this.route("new", { path: "/sign-in" }); | |
}) | |
}); | |
// However, any time you create a resource you have an extra layer of routing | |
// & a model that you may/may not want. In the case of sign-in, which doesn't | |
// really represent part of the UI, I'd consider just using a route instead. | |
App.Router.map(function(){ | |
this.route("signIn", { path: "/sign-in" }); | |
}); | |
// Then in your controller you can set the current session on ApplicationController | |
App.SignInController = Ember.Controller.extend({ | |
signIn: function(){ | |
var session = UserSession.validate(this.get("username"), this.get("password")); // assuming you have some object with a session token or something | |
this.controllers("application").set("session", sesssion); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/assets/javascripts/router.js.coffee | |
Projectile.Router.map (match) -> | |
this.route("signIn", { path: "/sign-in" }) | |
# app/assets/javascripts/controllers/signInController.js.coffee | |
Projectile.SignInController = Ember.Controller.extend | |
signIn: -> | |
console.log(this.get("email")) | |
console.log(this.get("password")) | |
session = Projectile.userSession.signIn(this.get("email"), this.get("password")) | |
#this.controllers("application").set("session", session) | |
# app/assets/javascripts/models/userSession.js.coffee | |
Projectile.UserSession = Ember.Object.extend | |
# has a signIn method that's getting called propertly. | |
Projectile.userSession = Projectile.UserSession.create() | |
# app/assets/javascripts/templates/signIn.handlebars | |
<div> | |
<label {{bindAttr for="emailField.elementId"}}>Email</label> | |
{{view Ember.TextField valueBinding='email'}} | |
</div> | |
<div> | |
<label {{bindAttr for="passwordField.elementId"}}>Password</label> | |
{{view Ember.TextField valueBinding='password' type='password'}} | |
</div> | |
<div> | |
<button {{action signIn}}>Login</button> | |
</div> | |
also just realized those labels won't work that way but i can fix that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This version is getting the form to display, routing properly and even calls into the user session object and hitting the server. all awesome.
problem - the 2 console.logs spit out "undefined". I can't get either the email or the password.