This file contains 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
puts 'SONNY..? IS THAT YOU..?' | |
input1 = '' | |
bye_count = 0 | |
while bye_count < 3 | |
input1 = gets.chomp | |
if input1 == 'BYE' | |
bye_count += 1 | |
puts 'NO. NOT SINCE '+(rand(1920..1956)).to_s | |
elsif input1.upcase == input1 | |
puts puts 'NO. NOT SINCE '+(rand(1920..1956)).to_s |
This file contains 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
#!/usr/bin/ruby1.9.1 -Kw | |
# -*- coding: utf-8 -*- | |
class Edge | |
attr_accessor :src, :dst, :length | |
def initialize(src, dst, length = 1) | |
@src = src | |
@dst = dst | |
@length = length |
This file contains 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.UserRoute = Ember.Route.extend({ | |
model: function(params) { | |
return this.store.find(user, params.user_id); | |
} | |
)}; |
This file contains 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.UserController = Ember.Object.Controller.extend({ | |
fullName: function() { | |
return this.get("first_name") + " " + this.get("last_name"); | |
} | |
}) |
This file contains 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.ProfilePhotoView = Ember.View.extend({ | |
click: function(evt) { | |
this.get('controller').send('ExpandProfilePhoto'); | |
} | |
}); | |
App.UserController = Ember.ObjectController.extend({ | |
actions: { | |
expandProfilePhoto: function() { | |
//get the expanded picture and display it |
This file contains 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
// in the controller | |
App.NumberController = Ember.ObjectController.extend({ | |
number: 1, | |
timesTwo: function() { | |
return Number(this.get('number')) * 2; | |
}.property('number') //tells it to treat it as a dynamic property that updates whenever number updates. | |
}); | |
//in the template | |
{{input type="text" value=number size=50}} x2 = {{timesTwo}} |
This file contains 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
1. User hits a URL | |
2. Ember's Router recognizes it and passes it to a Route object | |
3. The Route sets up a Controller and supplies it with a Model | |
4. The Model provides the View layer (represented by a Template) access to the data | |
5. Any properties defined by the Model are available to the Controller | |
ex: if User has first_name, your template has direct access to it through the Controller | |
*** don't need to define an empty controller method like in Rails *** | |
*** Ember will also generate the controller for you if one does not exist *** |
This file contains 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
// 1: Property method | |
App.NumberController = Ember.ObjectController.extend({ | |
number: 1, | |
timesTwo: function() { | |
return Number(this.get('number')) * 2; | |
}.property('number') | |
}); | |
// "property" lets you use the return value of a function as if it was a static value. | |
// if you add "property" to the end of your function and you can bind it to | |
// your template and display the value there. |
This file contains 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
# a rails controller set up to send user information to ember's profile page | |
class UsersController < Devise::SessionsController | |
def show | |
@user = User.find(params[:user_id]) | |
respond_to do |format| | |
format.json { render json: @user } | |
end | |
end | |
end |
This file contains 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
//For simple applications,, Ember Data's REST adapter can handle all | |
//asynchronous calls to the Rails server and completely insulate the | |
//dev from worrying about what happens when the server takes longer | |
//to respond than expected. | |
//If ever required to make a call to the server outside of a Route object's | |
//Model hook, you'll need to ensure that your application responds properly | |
//to when the call either fails or succeeds, and not to do anything about the | |
//call until it returns. |
OlderNewer