Ember no method save on this.get('store').save() - ember.js

Feel like I'm asking too much Ember questions lately, trust me I'm really trying by myself before every question and hopefully I'll get the whole picture going 'cause as of right now it's been two steps forward, one backwards.
This JSBIN ilustrates what I'm doing. It won't run since I can't load the localadapter_storage library, maybe there's a way to load it into jsbin but if that's so I don't know how to do it.
The problem I have is as follows:
I have the hability to create new posts and to edit old ones. When editing old ones I can't save the changes via this.get('store').save(); (have tried commit() also) since it says Uncaught TypeError: Object [object Object] has no method 'save' The save for the new posts is working properly.
I've compared the issue with other working examples of ember using the local adapter and I've tried to step by step ember.js and ember-data.js but I'm really not that versed yet. According to the error it's like it doesn't know where to apply the .save().

it should be record.save(). You don't need to access the store when you're saving, so in your case it would be something like, this.get('controller.model').save();

Related

Need to read Ember component property as array of model

I passed the result of this.store.findAll('something') to a component so I could create a dropdown control. Everything works great but I'd like to find the object I selected by reading this property.
Everything I read says its bad practice to inject the store into these components and since I already have the data in the property I thought it would be easy to read. However it's in an Ember model array that doesn't seem to be so easy to open because the array is deep down the stack.
I started heading down something like this.get('myprop').content... but I wondered if this was the correct way to do this. It seems I should be able to open them as the model they should be.
Any suggestions would be helpful.
it turns out the best way I could find to select my model was the 'peek' function. Not exactly what I wanted to do but it works.
Some of the comments below my initial question also work, but nobody ever actually added an answer so this is my answer. :-)

How to save relations of same class?

I had problem with saving relation to object with same class as parent.
You can check this problem here.
When I read that I can easily set the relationship after the promise has fulfilled here I created another example with that info in mind. But it doesn't work as I expect.
What I expect
Create array of Box instances with relation to previous Box instance in each.
And the question is if I'm doing something wrong or it's a bug. Let me know if you need any informations.
Your example isn't clear and simple enough. It needs to be isolated to EXACTLY what you're having an issue about and nothing else.
Having said that, I have had quite a bit of success saving relations to objects with the same class as parent, and so I don't think this is a problem with Ember Data or Ember.
Your code is quite convoluted and uses the sync library, which I'm not faimilar with.
It's a good idea to things as simply as possible at first, so try creating a jsbin with just the isolated functionality relating to saving relations that you're attempting, and then adding additional layers of functionality and testing after each add.

Why is my {{#each}} not working?

Why is the Ember Snippet i have linked not working? I am setting up a simple ArrayController and fill it with contents upon initialization. Then i want to display the contents of this controller with the help of {{#each}}, but this is not working.
In tutorials i have read through, the following structure is always used:
{{#each AppNamespace.myModelController}}
...
{{each}}
But to make my example work i had to use:
{{#each AppNamespace.myModelController.content}}
...
{{/each}}
Could you have a look at the provided fiddle and tell me what is wrong with it? I assume that i must have done something wrong since i have seen this pattern so often in tutorials.
Note: I am a Javascript beginner coming from Java Server Development. So it maybe easy JS basics that i am struggling with.
I would have posted the complete code here, but the formatting was not working properly.
Link to my JS Fiddle showing my problem
Add a call to this._super() inside your init method.
https://github.com/emberjs/ember.js/pull/1251
Also, not directly related to your question, but it looks like you would benefit from reading #6 here: http://codebrief.com/2012/03/eight-ember-dot-js-gotchas-with-workarounds/
Tried your fiddle with http://cloud.github.com/downloads/emberjs/ember.js/ember-0.9.6.min.js instead of 1.0 pre it is working fine in both the cases.
I'm starting to look at Ember myself and I'm concerned about the process you're using.
As far as I'm aware you shouldn't really be retrieving data directly from the controller like that. The pattern you use should be based upon models, controllers, views and the router.
http://trek.github.com/ is a resource which I have found useful while learning about Ember.
Based upon that example, this would be my take on a small ember test application:
http://jsfiddle.net/zDfBv/
Hopefully that will be of some use to you as a starting point.
If you pass 1 argument to the #each helper it needs to be a Ember.Array compatible object-- in your first example you pass the controller when your data is in the content property.. your second example works because you pass the content property.. and there is nothing wrong with doing it that way if you feel like it.
There is however an alternate syntax for the #each helper which you may see more often, it uses element naming {{#each model in myModelController}} ... {{/each}}. When you do it this way Ember takes care of looking for the content property for you because it's the default rendering context for the view.
Assuming you're using the latest version from Github you'll find it takes care of looking for content in both cases so the point becomes moot once that is released as stable.

Can't get Ember.js to render properties from objects in controller

Total Noob question here. My apologies for the simplicity, and I've skimmed hundreds of Ember-tagged posts here looking for an answer. But it appears to be too primitive for anyone to have bothered asking before...
I'm starting from scratch with Ember. I did Andy Matthews' EmberTweets tutorial, which worked fine. I'm trying to use that as a basis for my first Ember app, which is painfully simple; but I'm stuck on the most basic of steps. I appear to have a functioning controller, and am seemingly adding new objects to it successfully. But I cannot for the life of me get my view to render the properties of those objects. The basic view renders out, but not the data from the controller, which I'm just trying to access with a simple #each. I get no errors in any browser console.
Fiddle is here.
I've tried adding objects to the controller in three different ways in my example, to see if that helps. I can successfully access from the console the properties of the objects by inspecting the content array, or with something like FilterMenus.MenusController.content.objectAt(2).get('menu_name'). Apparently, the data is right where it's supposed to be.
But still nothing appears in my template when I try to render out any of the properties, such as: {{menu_name}}. What am I doing wrong, please?
As stated in the other answers, you have to declare your app as a global variable (by omitting the var).
Besides that, you are not calling this._super() inside your FilterMenus.menusController's init method. This is required to setup the Ember.ArrayController correctly, so modifying the content will work.
Besides these two issues, your code looks fine. Here's a working fiddle: http://jsfiddle.net/pangratz666/HPkHt/.
It seems like Ember's big problem with your code is that your Application is defined as a var so it can't be accessed from the template. Removing the var keyword helped.
For some reason though, that wasn't quite enough and I had to add a
this.set('content', []);
as the first line of your init function to get it to work. I've never had to do this before so I'm not sure if it's jsFiddle doing something. If anyone has some light to shed on this, I'd be keen to hear it.
Try the following:
Remove "var" from FilterMenus declaration:
FilterMenus = Em.Application.create();
Change the implementation of menusController.addMenu to be:
addMenu: function(menu) {
this.content.push(menu);
},
This got me the two menu names to show up after "Select Country" and the explanatory paragraph:
countries
countries2
Ember didn't seem to know what this.pushObject(menu); was. Pushing directly to the controller's content array will always work, though.

How to use backbone.js and jquery cloning to dynamically add and delete divs while making sure they display when back posting?

I have been struggling with this because I am new to backbone.js and am having difficulty creating this functionality. I have seen the examples such as todo.js on the backbone.js site which is similar, however I dont have the chance to test back posting with that. I was wondering if someone could give me a good idea of how to do this. I am using django with mongodb storage. All together I am struggling with:
1) Creating a rest api for backbone to use for storing in the db
2) Displaying the divs that I cloned to show up when I back post to the page.
For creating a rest api, I recommend checking out these two packages:
https://github.com/toastdriven/django-tastypie
http://django-rest-framework.org/
As far as updating the view after a post, I don't know if I get exactly what the problem is, but here is the third part of a good tutorial. The third part includes the full code. The WineListView illustrates how a list is updated when the model collection changes.