What is the correct way to define a model and route to build a model that can be used as application data.
App.Router.map(function(){ this.resource("main", {path:"/"}); }); App.MainRoute = Ember.Route.extend({ model:function(){ return App.Main.find(); } }); App.Main = DS.Model.extend({ appName:DS.attr('string') }); App.Store = DS.Store.extend({ revision: 11, adapter: DS.RESTAdapter.create({ namespace: 'api/v1' }) });
As a result, it calls api/v1/mains . But I want it to call api/v1/main , which returns the application data, which is the only object, e.g.
{ "appName":"MyApp", "lastLogin": "Sat May 11 2013 11:20:03 GMT+0530", ... }
I know about setting up the plural, but I think this is the wrong way to do this. Any help would be greatly appreciated. Thanks in advance.
EDIT: when setting up Plurals rendering template
App = Ember.Application.create(); App.Router.map(function(){ this.resource("main", {path:"/"}); }); App.MainRoute = Ember.Route.extend({ model:function(){ return App.Main.find(); } }); DS.RESTAdapter.configure("plurals", { main: "main" }); App.Store = DS.Store.extend({ revision: 11, adapter: DS.RESTAdapter.create({ namespace: 'api/v1' }) }); App.Main = DS.Model.extend({ "appName":DS.attr('string') });
json received from server
{ "main": { "app_name": "My App" } }
:
<script type="text/x-handlebars" data-template-name="main"> This is {{appName}} </script>
source share