Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DS.Model url not working in ember.js

I'm very, very, very new to Ember :-)

I have a DS.Model where I want to force the extension with .json, for retrieving the data from a Rails Server.

The url from the Server is working, and for I can see in the browser's debugger, the url is not what it's specified in the DS.model url

var App = Ember.Application.create();

App.store = DS.Store.create({
 adapter:  DS.RESTAdapter.create({url: 'http://127.0.0.1:3000'}),
revision: 8
});


App.Expedient = DS.Model.extend({
  url: 'expedients/%@.json',
  procedencia: DS.attr('string'),
  interessat_nom: DS.attr('string'),
  data_signatura_provisional: DS.attr('date')
});

Fetch the expedient manually:

var model2 = App.store.find(App.Expedient, 125000);

Output console:

OPTIONS http://127.0.0.1:3000/expedients/125000 404 (Not Found) 

I would like to be this url like this:

http://127.0.0.1:3000/expedients/125000.json 

Also I've tried to really change the DS.Model url with another different name like this:

App.Expedient.reopenClass({
 url: 'mockurl/%@.json'
});

But the browser's console has the same 'url' as before, I don't know why Ember-Data is not getting the model's url.

thanks!

regards,

ps. I'm aware of the Access-Control-Allow-Origin CORS problem when testing Ajax from two origins

like image 552
mongeta Avatar asked Nov 29 '25 20:11

mongeta


1 Answers

github isn't working right now, for some reason, so I can't look at the source for ember, but I think you can do something like this:

var adapter = DS.RestAdapter.extend({
  buildURL: function(record, suffix) {
    var s = this._super(record, suffix);
    return s + ".json";
  })
});

You'll need to plug this your store instead of the default rest adapter.

like image 87
jonnii Avatar answered Dec 02 '25 23:12

jonnii



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!