2012-07-17 148 views
2

這個問題看起來很簡單,但是放慢了我的工作速度!請幫我弄清楚我在哪裏犯了一個錯誤。如何提供Ajax發佈請求

我想建立一個使用Ruby-on-Rails的服務器,它將有一個主要的功能:爲我的客戶端JS提供一些數據的請求。然後使用jQuery的Ajax的方法來發送異步請求:

function processPeople() { 
     SOME.api(".get", {owner_id:frnds.response[i].uid,count:"3"}, function(posts) { 
           var usefulPosts = posts.response; 
           for (var i = 1; i <= 2; i++) { 

      $.ajax({ 
       type: 'POST', 
       url: 'wallposts', 
       data: {uid: usefulPosts[i]["from_id"], uniqpost_id: usefulPosts[i]["id"], tent:usefulPosts[i]["text"]} 
      }); 

    }; 
    }); 
    i++; 
    if (i<2) { 
     setTimeout(processPeople, 1000); 
    } 
} 

,在這裏我的控制器,其中POST請求被髮送:

def create 
    # debugger 

    if !(Wallpost.from_user(params[:uid]).find_by_uniqpost_id(params[:uniqpost_id])) 
    @newWP = Wallpost.new(:uid => params[:uid], :content => params[:content], 
      :uniqpost_id => params[:uniqpost_id]) 
    @newWP.save 


end 

如果我想只是爲了節省服務器端並沒有什麼更多的數據是什麼,有什麼我會在服務器端做什麼?每次我嘗試發佈信息到我的服務器它回答了我500錯誤:

ActionView::MissingTemplate (Missing template wallposts/create, application/create with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:erb, :builder, :coffee]}. Searched in: 
    * "/home/yurgen/rails_project/vkraigslist/app/views" 

回答

1

你需要指定控制器的回報。 HTTP協議請求。

如果你不想返回任何代碼,只需把

head :ok 

在控制器結束。

+0

謝謝!這是工作。 – 2012-07-18 07:12:31