【问题标题】:Ember not sending a DELETE on destroyRecord()Ember 未在 destroyRecord() 上发送 DELETE
【发布时间】:2015-06-27 22:54:36
【问题描述】:

在让 activeModelAdapter 在 .destroyRecord 上发送 DELETE 请求时遇到问题,我也尝试使用 .save() 进行 .deleteRecord,但得到相同的结果....

我已经安装了 rack-cors gem,所以我的 api 已经排除了跨域请求

错误:

在 2015 年 4 月 20 日 17:51:05 -0700 开始为 ::1 的选项“/brands/117”> ActionController::RoutingError(没有路由匹配 [OPTIONS] “/brands/117”):

品牌管理者:

export default Ember.ArrayController.extend({
     needs: 'application',
     currentUser: Ember.computed.alias('controllers.application.currentUser'),
     currentPath: Ember.computed.alias('controllers.application.currentPath'),
     actions: {
        deleteBrand: function(brand) {
           brand.destroyRecord();
        }
     },
     showButton: function() {
        return this.currentPath === 'brands';
     }.property('controllers.application.currentPath')
});

品牌模板:

<h2>Brands</h2>

{{#if showButton}}
    {{#link-to 'brands.new' class="bam-btn submit login" tagName="button"}}Create A Brand{{/link-to}}
{{/if}}

{{outlet}}

{{search-brands}}

{{!-- LIST OF BRANDS --}}

<h2 class="bam-clear">List of {{ controllers.application.currentUser }} brands</h2>

<ul>
    {{#each brand in model}}
        {{#link-to 'brand.dashboard' brand.slug}}
         <li><h3>{{brand.brand_name}}</h3></li>
         <button id="deleteBrand" class="bam-btn alert" {{action 'deleteBrand' brand}}>Delete</button>
         {{/link-to}}
    {{/each}}
 </ul>

【问题讨论】:

标签: ruby-on-rails ember.js


【解决方案1】:

只需在我的 RACK::Cors 配置中包含 :delete 方法即可。

config/application.rb:

config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '*'
    resource '*', headers: :any, methods: [:get, :post, :delete, :options]
  end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多