2017-02-13 1 views
0

「確認」ボタンがあるページがあります。クリックするとJSON RESTアダプタを使用してネットワークに保存されます。ember-data model.saveは関数ではありません

/accounts/[email protected]/verification 
/accounts/{email}/verification 

しかし、「model.saveは関数ではありません」というエラーが表示されています。

Uncaught TypeError: model.save is not a function 
    at Class.verifyEmail (index.js:19) 
    at Router.triggerEvent (ember.debug.js:28654) 
    at trigger (ember.debug.js:55917) 
    at Router.trigger (ember.debug.js:57517) 
    at Class.send (ember.debug.js:27844) 
    at Class.send (ember.debug.js:31852) 
    at ember.debug.js:11639 
    at Object.flaggedInstrument (ember.debug.js:18475) 
    at ember.debug.js:11638 
    at Backburner.run (ember.debug.js:717) 

テンプレート/アカウント/ショー/検証/ index.hbs:

<section class="main-content"> 
    <div class="container-fluid" style="border:1.0rem solid #fff;"> 
    <div class="row"> 
     <div class="col-xs-12 col-sm-7 col-lg-6"> 
     <form {{action "verifyEmail" on="submit"}}> 
      <div class="form-group"> 
      <h2>Confirm your email now to complete the registration</h2> 
      </div> 

      <div class="mt10"> 
      <button type="submit" class="btn btn-success">CONFIRM NOW</button> 
      </div> 
     </form> 
     </div> 
    </div> 
    <div class="row mt20"> 
     <div class="col-xs-12 col-sm-7 col-lg-6"> 
     You are receiving this email because ... 
     </div> 
    </div> 
    </div> 
</section> 

router.js:

import Ember from 'ember'; 
import config from './config/environment'; 

const Router = Ember.Router.extend({ 
    location: config.locationType, 
    rootURL: config.routerRootURL 
}); 

// page route 
Router.map(function() { 
    this.route('accounts', function() { 
    // /accounts/new 
    this.route('new', function() { 
     //this.route('success'); 
    }); 

    this.route('show', { path: '/:account_id' }, function() { 
     // /accounts/1/confirmation 
     this.route('confirmation'); 
     // /accounts/1/verification 
     this.route('verification', function() { 
     // /accounts/1/verification/success 
     this.route('success'); 
     }); 
    }); 
    }); 
}); 

export default Router; 

ルート/アカウント/ショー/検証/ index.js:

import Ember from 'ember'; 

export default Ember.Route.extend({ 
    model: function(params) { 
    return this.store.createRecord('account-verification'); 
    }, 

    actions: { 
    /* account email verification */ 
    verifyEmail() { 
     var model = this.get('model'); 

     var self = this; 

     <<<<<PROBLEM HERE, "MODEL.SAVE IS NOT A FUCTION">>>>> 
     model.save().then(function(data) { 
     // handle success 
     // route user to success page 
     }).catch((adapterError) => { 
     console.log(adapterError); 
     }); 
    } 
    } 
}); 

モデル/ account-verification.js:ルート内の

import DS from 'ember-data'; 

export default DS.Model.extend({ 
    email: DS.attr('string'), 
    secretToken: DS.attr('string') 
}); 

答えて

2

this.get('model')あなたはmodel方法によって作成されたレコードにないmodel機能を返します。したがって、このアクションを対応するコントローラーに移動するか、controllerForを使用してコントローラーからモデルを取得する必要があります。

コントローラ/ accounts/show/verification/index.jsファイルにアクションを移動します。

import Ember from 'ember'; 
export default Ember.Controller.extend({ 
    actions: { 
     /* account email verification */ 
     verifyEmail() { 
      var model = this.get('model'); 
      var self = this; 
      model.save().then(function(data) { 
       // handle success 
       // route user to success page 
      }).catch((adapterError) => { 
       console.log(adapterError); 
      }); 
     } 
    } 
}); 
+0

ありがとうございます、私はこれを回答として受け入れています。コントローラに移動しています。あなたはまた、ルート上でverifyEmail()を動作させる方法も示すことができますか? –

+0

これを試してください 'var controller = this.controllerFor(this.routeName); var model = controller.get( 'model') ' – kumkanillam

+0

または' var controller = this.controllerFor( 'accounts.show.verification.index'); var model = controller.get( 'model') '@OhChinBoonはあなたのために働いていないかどうか私に教えてください。 – kumkanillam

関連する問題