cerebris / ember-rest Goto Github PK
View Code? Open in Web Editor NEWSimple RESTful resources in Ember.js
License: MIT License
Simple RESTful resources in Ember.js
License: MIT License
For example:
App.User = Ember.Resource.extend({
resourceUrl: '/users',
resourceName: 'user',
resourceProperties: ['name', 'selected']
});
App.UserController = Ember.ResourceController.extend({
selecteds: function(){
var users = this.get('content');
return users.filterProperty('selected', true);
}.property('[email protected]')
})
As the propery 'selected' is not prepared for Ember when initializing the observer, the property binding on '[email protected]' won't work any more.
To fix the problem, you should declared the property you wanna binding explicitly, such as:
App.User = Ember.Resource.extend({
resourceUrl: '/users',
resourceName: 'user',
resourceProperties: ['name', 'selected'],
selected: false
});
I suggest the author to add this trick on the README.md, since l think lots of people will encounter this issue.
hey there
i'm new to ember and setup a very simple site using ember-rest and was pleasantly surprised when (with the help of the rack-cors gem) i was able to build a simple ember.js app that pulled data from site1 (rails) and displayed it on site2 (ember).
Great work.
I've just started filling out the app and wanted to move to a package manager system. It seems that bpm doesn't have a copy of your wonderful library. are you planning to release it as a bpm package? soon? if not, let me know and i might just do that for my own sanity.
Cheers
Mr Rogers
Currently, there is no option to specify the namespace for resource URL. People can reopen ResourceAdapter to add namespace:
Ember.ResourceAdapter.reopen({
ns: 'json/v1'
});
However Ember-REST still need to be changed to accept this namespace:
_resourceRequest: function(params) {
params.url = this.ns + this._resourceUrl();
...
...
}
It appears that rails 3.2 implements render :json a bit differently than rails 3.1 did for arrays -- it generates an object with a property named after the resource instead of just returning a json array.
So instead of [], you get {resources: []}
This breaks findAll for me. I fixed it by overriding findAll in my controllers. I'm not sure what a good overall fix would be, however, as there is currently no setting with the plural form of the resource name, which is what is required to access the array inside the returned json object.
Here's my crappy fix for my categories controller:
findAll: function(){
var self = this;
return this._resourceRequest({type: 'GET'})
.done(function(json) {
self.clearAll();
self.loadAll(json.categories);
});
}
When calling the ResourceController findAll() function, it doesn't find the resourceType's resourceUrl and thus gives 404 error on '/undefined' for the ajax call.
Ember.Object uses destroy. You should rename Ember.Resource#destroy to something like destroyResource and similarly with the save method so they are named consistently.
when i call .destroyResource() in an Em.Resource object, it fires the function 2 times, so generates 2 DELETE xhr requests.
I checked the button that fires the function that calls destroyResource, and its ok, calling it just one time, so i think it might be a issue with ember-rest.js. Any clue?
the code:
App.user = Em.Resource.extend({
resourceUrl:"testObjects.php",
resourceIdField:"_id",
resourceProperties:['nome','email','id','senha']
});
App.users = Em.ResourceController.create({
resourceUrl:"testObjects.php",
resourceType:App.user
});
App.novoUsuarioView = Em.View.extend({
criar:function(){
var novoUsuario = App.user.create({nome:this.get("nome"), email:this.get("email"), senha:this.get("senha"), status:0});
App.users.load(novoUsuario);
novoUsuario.saveResource();
App.log(novoUsuario.getProperties("nome","email", "senha"));
},
load:function(){
App.users.findAll();
}
})
App.usersView = Em.View.extend({
contentBinding:'App.users',
didInsertElement:function(){
var self = this.$();
self.find(".showUser").hover(function(){
$(this).stop(true).animate({
backgroundColor:"#bbb"
},200)
$(this).find(".userOptions").stop(true,true).fadeIn(200);
}, function(){
$(this).stop(true).animate({
backgroundColor:"#ddd"
},100)
$(this).find(".userOptions").stop(true,true).fadeOut(100);
});
self.find(".edit").click(function(){
self.find(".editUser").show(0);
});
self.find(".cancel").click(function(){
self.find(".editUser").fadeOut(200);
})
},
templateName:"usuarios",
removerUsuario:function(){
console.log("chamou a action");
var object = this.get("usuario");
this.$("div:first-child").slideUp(100, function(){
//App.users.destroyResource(object);
object.destroyResource().fail(function(e){
console.log("Error");
console.log(e);
}).done(function(e){
App.users.removeObject(object);
console.log("success!");
console.log(e);
});
});
},
editarUsuario:function(){
var usr = this.get("usuario");
view.appendTo("#holder");
}
})
I use MongoDB so in model _id is a property not function .. so i get this error:
Uncaught TypeError: Property '_id' of object App.Contact:ember454 is not a function
How can i solve that?
Add version to Ember-REST with compatible Ember.JS versions in the documentation.
Sorry I didn't include a pull, I don't know what versioning scheme you rather use, which version it is supposed to be now and which Ember.JS versions it is supposed to be compatible with.
The ResourceController objects can only access it's default resourceUrl (resourceType object's resourceUrl) only if the resourceType object is created, don't work if its just extended, otherwise, i have to define it manualy in the ResourceController object. Its the intended behavior?
When i have a name property like this :
App.Contact = Ember.Resource.extend({
url: '/contacts',
name: 'contact',
properties: ['name'],
....
The name property is being used in the json as :
{"value of property name"=>{"name"=>"value of property name"}
when i post a form using the edit template
{{#with contact}}
{{view Ember.TextField valueBinding="name" placeholder="name"}}
{{#if id}}
{{submitButton "Update"}}
{{else}} {{submitButton "Create"}}
{{/if}}
{{/with}}
thanks a lot for all the help
I'd like to update paramaters, for example set a field true to false, however, whenever I call saveResource(), I am creating a new record in the database rather than update an existing one.
Is this an alternative to ember-data? It seems to provide similar capability.
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.