2013-06-21 26 views
0

請求如何張貼到軌服務器的請求時,點擊「查詢」按鈕emberjs +軌道,如何指定路線,併發布到軌服務器

軌道路線

resources :sentences do 
    member do 
    get :check 
    end 
end 

軌句子控制器

class SentencesController < ApplicationController 

    def check 
    render json: false 
    end 

end 

emberjs路線

App.Router.map -> 
    @resource "sentences", -> 
    @resource "sentence", 
     path: ":sentence_id", -> 
     @route "check" 

emberjs模板

<script type="text/x-handlebars" id="sentence"> 

    <button {{action 'check'}} class='btn'>Check</button> 

</script> 

回答

0

我覺得你要做的是違背約定。

下面是應該的,這是由你只是在你的模型更新「檢查」變量(糾正我,如果我錯了)的前提下去。

在餘燼方面:

路由器:

App.Router.map(function() { 
    this.resource('sentences', function() { 
    this.resource('sentence', {path: ':sentence_id'}); 
    }); 
}); 

的控制器

App.SentenceController = Ember.ObjectController.extend({ 
    check: function() { 
    var sentence = this.get('model'); 
    sentence.set('check', true); 
    sentence.get('store').commit(); 
    } 
}); 

模板:

<script type="text/x-handlebars" id="sentence"> 
    <button {{action 'check' on="click"}} class='btn'>Check</button> 
</script> 

然後在鐵軌邊,你可以得到擺脫從路線和控制器,只是檢查行動使用默認的端點(在這種情況下,當你的從灰燼應用程序提交它會把更改使用sentences#update/sentences/:id/update.json您的Rails應用程序)。