ember.js Ember未在destroyRecord()上发送DELETE

jum4pzuy  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(162)

在让activeModelAdapter在.destroyRecord上发送DELETE请求时遇到了问题,我也尝试了使用.保存()的.deleteRecord,但得到了相同的结果....
我已经安装了rack-cors gem,所以我的api已经排除了跨源请求

错误:

开始选项“/brands/117”用于::1于2015-04-20 17:51:05 -0700〉操作控制器::路由错误(没有路由匹配[选项]“/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>
oaxa6hgo

oaxa6hgo1#

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

  • 配置/应用程序.rb:*
config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '*'
    resource '*', headers: :any, methods: [:get, :post, :delete, :options]
  end
end

相关问题