1
我想通過GET方法調用我的服務器動作/用戶/菜單,但它只能與REST代理一起工作。使用Extjs Ajax代理與rails rest服務器
這裏是我的商店聲明:
Ext.define('App.store.Menu', {
extend: 'Ext.data.Store',
model: 'App.model.Menu',
proxy: {
type: 'ajax',
reader: {
type: 'json'
},
api: {
read: 'users/menus'
}
}
});
,這裏是我如何裝載存儲:
var store = Ext.create('App.store.Menu').load({
id: 1,
callback: function() {
//do something...
}
});
,這是我的Rails代碼:
def menus
@user = User.find(params[:id])
@menus = @user.menus
respond_to do |format|
format.html # menus.html.erb
format.json { render json: @menus }
end
end
我得到這個服務器上的錯誤:
ActiveRecord::RecordNotFound (Couldn't find User with id=menus):
app/controllers/users_controller.rb:16:in `show'
但是,如果使用REST代理,我得到正確的請求:
Ext.define('App.store.Menu', {
extend: 'Ext.data.Store',
model: 'App.model.Menu',
proxy: {
type: 'rest',
format: 'json',
url: 'users/menus'
}
});