EmberJs: Update the Data Store Schema - ember.js

I'm currently developing an Ember application and I've come across a blocker...
I am loading my data from a RESTful api and this was working a treat, but I have now updated one of my models with 2 new fields. The server is returning the new json format and it includes the new field. DS.Model consumed by the ember application also contains the new fields but when I view the Data in the chrome plugin, the schema does not seem to reflect the changes to the model. I have tried clearing the cache in the browser but it does not seem to force the schema to update.
Any pointers?

Ok I have done a bit more digging and it seems to be an issue with the Chrome plugin
The datagrid view does not display the new columns but if you drill into the rows then the attributes ARE being shown, this has at least pointed me in the correct direction.

Related

How to auto-refresh the templates(or better views) whenever data is updated in models?

I am working on a project which sends data to django server using POST request (not through web browser) and updates data on models.
My templates just runs through all the data in models and print it in a table.
The problem here is that I've to manually refresh my page to get the updated data.
I want my page to auto-update the data entered into models.
I'm very new to django, so is there a way to achieve this?
(I'll post the codes if needed)

Backand queries, tables etc. not in sync, but actual data is

I'm having a weird issue with Backand. I created an app, a couple of tables, inserted data, and created a query using their web frontend. Integrated Backand in my Ionic2 app, worked great. A few hours later I added a couple of queries, and got the error message that the object doesn't exist when using the query. I changed the query I used successfully earlier, and got the same result as before the change - so the changes to my queries where not synced to the server (I'd assume). I added a field to a table I did this.backand.object.getList('items') before, but the field was missing. Strangely the data I am adding to the tables, or changing is correctly shown in both my app, and the web frontend.
In summary - data is the same in web frontend and my app, any changes to data model, or queries are shown in web frontend but not in the app.
Anyone has seen that before?
Never mind, 8 hours later everything is in sync. My query can be used in the app, changes to the data model are also seen by the app (through the API).

Where to collect data from the web in Rails 4 MCV

I'm building a rails application where I parse some html data on the web and then save it in my database, the data is saved in multiple models though. I'm currently doing that in the controller, but I'm not sure where I should do it in the MCV model!
You are doing it well, the work of the controllers is get the data from users, aply some logic and save it on database.
The model work is to ensure that data is correct and understanable and work as gateway between ruby classes and database tables.
Here you can find more information about MVC
http://projectmanagementdud.blogspot.com.es/2013/03/model-view-controller-mvc-simply.html
In your case you're parsing data in your controller and this controller save data on multiple models, this is accepted, one controller is not obligated to interactue only with one model, if isn't, save data in the models with the same action will be impossible, a good practice is to choose this controller with wisdom :).

How do I access the URL that Ember Data will PUT to?

I'm adapting an old JS (no framework) + Rails app as an Ember learning exercise. The idea of the application is that I'm producing a pdf from some data input. In the initial version, there was no user persistence - you could modify the data provided to you in the tables, and then download the PDF of it.
As part of this, I decided to run with a decidedly non-standard ember framework - I'm essentially using Ember Data to load the initial value of the tables. Ember has been a really natural fit for the models I have on the Rails side, and it's made a lot of the more complicated calculations a lot easier. The issue I have is that my initial idea was that when I came to download the PDF, I'd respond to the "save" action on Ember Data with binary data (with an application/pdf header), which I could then use something like FileSaver.js to serve up to the client. Then, I found that EmberData needs JSON return value.
So I base64 encoded my PDF response and fired it back..but it didn't fit the model schema. I thought I'd then do a manual AJAX save -
CalculateYourTV.RostersShowController = Ember.ObjectController.extend({
actions:{
download: function(){
var roster = this.get("model");
var team = roster.get('team');
return this.ajax('*URL GOES HERE*', record.toJSON(), "PUT").then(function(data) {
console.log('called')
console.log(data)
});
},
}
})
And this is where I'm currently stuck. Is there any way to access the URL that EmberData is posting to? I could hard-code a route in the Rails side of things, but I don't like hardcoding routes in here, and I'd like to keep it as reusable as possible (I'm planning to eventually allow data persistance).
Just open chrome dev tools (or firebug) and monitor what's going on in the network tab. You should see any ajax request your application sends out, including the EmberData's save request.
You can change the URL that a specific model will hit by creating custom Ember Data adapters per model.
For example, say you have a person model that needs to not hit the default /persons URL.
App.PersonAdapter = App.ApplicationAdapter.extend({
pathForType: 'special/custom/endpoint/for/folks'
});
That said, Ember Data may not be the best tool here for your PDF "model". You can always use Ember Data for the majority of your models, but use a quick $.ajax for other stuff that doesn't fit your definition of a true model.
You can ask the adapter to build a URL for you -
adapter = #store.adapterFor('application')
url = adapter.buildURL(type, id)
where type is the name of the model, and id is its id.
If want to look up the adapter directly in the container it is
#container.lookup('adapter:application')

Django Rest/Ember How to connect to models

I am getting started with Ember, and Django Rest Framework and I can't seem to peice together how to connect a model so that Ember can use the data in that model and create a simple drop down box. I have one model that I am starting with that is as such:
id
name
security
status
All I want to achieve is allowing Ember to use the data in this model and create a dropdown like so.
<select id="model">
<option value="model.ID">model.Name</option>
</select>
Can anyone help me with this? I am complete new to Ember and Django Rest.
Without going into a ton of detail, I've created a mini example of what you're looking for
http://emberjs.jsbin.com/Ozimatuj/2/edit
You'll note that I'm using mockjax, so instead of hitting any real endpoint, it's all mocked. Additionally I'd recommend using a client side record management solution (such as ember-data or ember-model). That's another discussion though.
In the application route (which correlates with the root of your app) it hits the model hook (which should return the model associated with that route. I'm returning a POJO of the users. That model is being assigned as the content of the application controller (automatically generated). The the application template is being built, and it's being backed by the application controller. Inside the application template we create an instance of ember select, and we tell it that the content backing it is model (which is the model/content in the application controller). We also say, use bind the user model (you could do id) and the name to the value and the label respectively.
I then bound the value of the select to selectedPerson, so anytime the value changes, the selectedPerson updates, the template which talks about that person will update. Magic. Ember does the rest.
This is a really broad question, so if you have any other questions, please ask a specific question, and I'd really recommend going through the getting started guide, it's really short, but will give you a decent foundation of terminology and methodology of Ember. http://emberjs.com/guides/getting-started/
For Ember Data I'd do a quick read the of the transition document for ED 1.0 beta.
https://github.com/emberjs/data/blob/master/TRANSITION.md
DS.DjangoRESTSerializer = DS.RESTSerializer.extend();
DS.DjangoRESTAdapter = DS.RESTAdapter.extend({
defaultSerializer: "DS/djangoREST"
});