小编Sei*_*lam的帖子

如何为所有RESTAdapter余提请求添加标头

API需要指定api版本application/vnd.api+json;version=1,它还需要安全的x-app-id和x-app-secret.有没有办法在Ember的RESTAdapter中指定它?

尝试请求标头后

App.Adapter = DS.RESTAdapter.extend({
  namespace: 'api',
  beforeSend: function(xhr) {
    xhr.setRequestHeader('x-my-custom-header', 'some value');
  }
})
Run Code Online (Sandbox Code Playgroud)

App.Adapter = DS.RESTAdapter.extend({
  bulkCommit: true,
  namespace: 'api',
  headers: { 
   'Accept': 'application/vnd.app+json;version=1',
   'x-appid': '2375498237',
   'x-secret': '238945298235236236236236375923'
  },
  ajax: function(url, type, hash) {
    if (this.headers !== undefined) {
      var headers = this.headers;
      hash.beforeSend = function (xhr) {
        Ember.keys(headers).forEach(function(key) {
          xhr.setRequestHeader(key, headers[key]);
        });
      };
    }
    return this._super(url, type, hash);
  }
});

App.Store = DS.Store.extend({ adapter: App.Adapter.create() }); 
App.Store = App.Store.create();
Run Code Online (Sandbox Code Playgroud)

更新#2

不再需要上面提到的解决方案,因为Ember现在默认支持此行为.您只需要提供headers,它将自动添加.

查看这里的文档 …

ember.js ember-data

13
推荐指数
1
解决办法
9712
查看次数

蒙古族的暧昧关系

我正在尝试在Post模型中将viewer_ids保存为user_ids,并将User模型中的Viewed_ids保存到已查看的post_ids.当使用Rspec进行测试添加/删除并访问来自User的关系时,它很有用.但是当我使用RABL来查看post-while用户数据时,它会被混淆并给我一个不明确的关系.

#Post class
belongs_to :user
has_and_belongs_to_many :viewers, class_name: 'User', inverse_of: :viewed  

#User class
has_many :users
has_and_belongs_to_many :viewed, class_name: 'Post', inverse_of: :viewers
Run Code Online (Sandbox Code Playgroud)

邮件#show中的Mongoid :: Errors :: AmbiguousRelationship

Problem:
Ambiguous relations :posts, :viewed defined on User.
Summary:
When Mongoid attempts to set an inverse document of a relation in memory, it needs to know which relation it belongs to. When setting :user, Mongoid looked on the class Post for a matching relation, but multiples were found that could potentially match: :posts, :viewed. …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails mongodb mongoid

7
推荐指数
1
解决办法
1412
查看次数

Mongoid文件生存时间

有没有办法为文档设置时间,然后它就会被销毁.我想创建每个会话临时的访客用户,因此一周后文档会自动删除.

ruby-on-rails mongoid

6
推荐指数
1
解决办法
2382
查看次数

Linux下的流量整形

在哪里可以了解如何在Linux下控制/查询网络接口?我想获得特定的应用程序上传/下载速度,并强制执行特定应用程序的速度限制.

我特别喜欢可以帮助我使用Python编写流量整形应用程序的信息.

python linux ubuntu trafficshaping

5
推荐指数
2
解决办法
3700
查看次数