煎茶触摸的Rails 3.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 }
}
})
答
如果你的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
模型。