Sencha Touch Rails 3.1

我正在尝试在rails上加载带有sencha touch的资源,但是我收到以下错误:

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 } } }) 

如果您的Rails代码如下所示,那么问题可能是使用的OPTIONS方法 – index操作仅响应GET 。 你知道为什么在这里使用OPTIONS吗? 我在Sencha Touch文档中找不到这个数据存储。

 # 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 

顺便说一句:从我在这里看到的,您应该将代理代码移动到MenuItem模型中。

OPTION请求是跨源资源共享(CORS)协议的一部分。 检查这篇有价值的post 。 您可以使用rack-cors gem轻松配置它。