如何从ember.js前端删除/销毁rails API后端中的记录

时间:2015-10-29 22:00:36

标签: ruby-on-rails api ember.js

我有一个包含各种记录的rails API后端,我希望能够从ember.js前端删除它们。我可以使用ember.js显示记录但是当我单击我通过ember添加的delete按钮时,记录不会在rails后端中删除。当我点击delete按钮时,我甚至没有看到控制台中rails服务器的任何活动。

余烬

// app/routes/index.js

import Ember from 'ember';

export default Ember.Route.extend({
    model: function() {
        return this.store.find('csv-file');
    },
    actions: {
        delete(csvFile) {
            // debugger;
            csvFile.destroyRecord();

            // csvFile.save();
        }
    }
});

// app/models/csv-file.js

import DS from 'ember-data';

export default DS.Model.extend({
    csv_file_filename: DS.attr('string')
    // id: DS.attr('int');
});

// app/templates/csv-files/index.hbs

<h3>Hi CSV Files</h3>
<ul>
    {{#each model as |csv|}}
        <li>
            {{csv.id}} - {{csv.csv_file_filename}}
            <button {{action 'delete' csvFile}}>Delete</button>
        </li>
    {{/each}}
</ul>

# csv_files_controller.rb

# DELETE /csv_files/1
  # DELETE /csv_files/1.json
  def destroy
    @csv_file = CsvFile.find(params[:id])
    if @csv_file.destroy
      render :json => { :head => ok }, status: 200
    else
      render json: {error: "csv file could not be deleted."}, status: 422
    end
  end

0 个答案:

没有答案