flyptkarsh / gotyaa Goto Github PK
View Code? Open in Web Editor NEWProject Three Twilio Rails App
Project Three Twilio Rails App
I am using $resources to make calls to my rails database. The calls work, but rather than returning a JSON object I can use they return a $promise, with all the data I need, but that I cannot iterate through.
I have been looking at various tutorials on working with promises
http://www.html5rocks.com/en/tutorials/es6/promises/
https://docs.angularjs.org/api/ng/service/$q
http://andyshora.com/promises-angularjs-explained-as-cartoon.html
What I get in Chrome
$promise: Object, $resolved: false]0: Resourcecontent: "My pants are on fire"created_at: "2014-09-01T18:00:23.276Z"id: 1updated_at: "2014-09-01T18:00:23.276Z"user_id: 1__proto__: Resource1: Resource2: Resource3: Resource4: Resource5: Resource6: Resource7: Resource8: Resource9: Resource10: Resource11: Resource12: Resource13: Resource14: Resource15: Resource16: Resource17: Resource18: Resource19: Resource$promise: Object$resolved: truelength: 20__proto__: Array[0]
My application.js
// creates the entire angular application
var app = angular.module('GotyaaApp', ['ngResource', 'templates'])
// configures $resource for the factories
.config(['$resourceProvider', function ($resourceProvider) {}])
// factory for making ajaxy angular calls to the message database
.factory('GotYaas', ['$resource', function($resource) {
return $resource('http://localhost:3000/got_yaas', null,
{});
}])
// controls adding the message and creating a new gotyaa
.controller('GotyaaController', ['$scope', 'GotYaas', function($scope, GotYaas) {
var gotYaasPromise = GotYaas.query();
console.log(gotYaasPromise);
$scope.messages = [];
// adds the content to the message
$scope.submit = function() {
if ($scope.smsContent) {
$scope.messages.push(this.smsContent);
$scope.smsContent = '';
}
};
I am getting a 422 error when I try to submit my post request.
I think it is because my post request is in HTML and not JSON but I do not know how to change it.
I have been looking at the Angular documentation for $resources.
https://docs.angularjs.org/api/ngResource/service/$resource2
Which says a post request should look like this...
// we can create an instance as well
var newCard = new CreditCard({number:'0123'});
newCard.name = "Mike Smith";
newCard.$save();
// POST: /user/123/card {number:'0123', name:'Mike Smith'}
// server returns: {id:789, number:'0123', name: 'Mike Smith'};
expect(newCard.id).toEqual(789);
From my app.js
$scope.saveMessage = function(message, current_user_id ){
var newGotyaa = new GotYaas();
newGotyaa.user_id = current_user_id;
newGotyaa.content = message;
newGotyaa.$save();
};
POST http://localhost:3000/got_yaas 422 (Unprocessable Entity) angular.js?body=1:8540(anonymous function)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.