2010-01-11 88 views
0

我正在Rails中開發其他應用程序,並且遇到問題。我送AJAX POST請求軌休息應用Rails,Rest - 如何從ajax調用獲取發佈數據

update_feedback : function(attrs, success, error){ 
    $.ajax({ 
     url: '/sync/feedback', 
     type: 'post', 
     dataType: 'json', 
     success: success, 
     error: error, 
     data: attrs, 
     fixture: false 
    }) 
} 

的WEBrick服務器說

Processing Sync::FeedbackController#create (for 127.0.0.1 at 2010-01-11 15:11:33) [POST] Parameters: {"created_at"=>"2009/11/15 12:37:49 +0100", "blog_name"=>"null", "title"=>"null", "guid"=>"74a27fb2-0e36-4ff0-a77e-5b9617a7549d", "body"=>"test", "author"=>"tibor"} 

現在我不知道,如何在Rails應用程序POST請求獲取數據。例如,我需要獲取作者參數或創建新評論。我試過這個代碼,但它不起作用

def create 
    @comment = Feedback.new params[:post] 
    @comment.save 
    end 

我的休息的應用程序正在工作,所有得到的請求工作得很好。我怎樣才能得到所有參數和每個參數。感謝您的幫助。

回答

1

什麼是您的表單ID?如果按照標準創建,您的反饋參數將命名爲例如:

def create 
    @comment = Feedback.new params[:feedback] 
    @comment.save 
end