2011-11-28 112 views
1

我試圖加載與在軌道上煎茶觸摸的資源,但我得到了以下錯誤:煎茶觸摸的Rails 3.1

Started OPTIONS "/menu_items.json?_dc=1322512349038&limit=25&sort=%5B%7B%22property%22%3A%22name%22%2C%22direction%22%3A%22ASC%22%7D%5D" for 127.0.0.1 at 2011-11-28 18:32:29 -0200 

ActionController::RoutingError (No route matches [OPTIONS] "/menu_items.json"): 

我的店鋪代碼:

new Ext.data.Store({ 
       model: 'MenuItem', 
       sorters: 'name', 
       getGroupString: function(r){ 
        return r.get('name')[0] || ""; 
       }, 
       proxy: { 
        type: 'rest', 
        url: 'http://localhost:3000/menu_items', 
        format: 'json', 
        reader: { 
         type: 'json', 
         root: 'menu_item' 
        } 
       }, 
       listeners: { 
        load: { fn: this.initializeData, scope: this } 
       } 
      }) 

回答

0

如果你的Rails代碼如下像下面的東西,那麼問題可能是OPTIONS方法 - index行動只響應GET。你知道爲什麼在這裏使用OPTIONS嗎?在煎茶觸摸實況的數據存儲我找不到這個..

# config/routes.rb 
# ... 
resources :menu_items 

# app/controllers/menu_items_controller.rb 
class MenuItemsController < ApplicationController 
    def index 
     @menu_items = MenuItem.all 

     respond_to do |format| 
     format.json { render :json => @menu_items } 
     end 
    end 
end 

BTW:從我所看到的here,你也許應該移動代理代碼到MenuItem模型。

0

OPTION請求是跨源資源共享(CORS)協議的一部分。有關它的檢查this valuable post。您可以使用rack-cors gem輕鬆配置它。