1

What I have done -

Model -

App.Book = DS.Model.extend({
   book_name: DS.attr('string'),
   edition: DS.attr('string')
});

Router -

App.Router.map(function() {
   this.resource('books', function() {
      this.route('new');
   });
});


App.BooksNewRoute = Ember.Route.extend({
    model: function() {
        return this.store.createRecord('book');
    },

    actions: {
       save: function() {
          this.modelFor('newBook').save();
       }
    }
});

Now Can anybody help me.. How to save data ?

I am getting error like

TypeError: this.modelFor(...) is undefined
this.modelFor('newBook').save();
user2709881
  • 145
  • 1
  • 1
  • 9

2 Answers2

0

It is hard to tell how the context of your action looks like.

But one option is to pass the object you want to save as a parameter like this {{action save myBook}}.

Then you action could look like this:

App.BooksNewRoute = Ember.Route.extend({
    model: function() {
        return this.store.createRecord('book');
    },

    actions: {
       save: function(book) {
          book.save();
       }
    }
});
Mutual Exception
  • 1,240
  • 12
  • 27
0

I think this should work.

App.BooksNewRoute = Ember.Route.extend({
    model: function() {
        return this.store.createRecord('book');
    },

    actions: {
       save: function() {
          this.get('model').save();  
       }
    }
});
gordonc
  • 532
  • 4
  • 8