【问题标题】:Sencha Touch Rails 3.1Sencha Touch Rails 3.1
【发布时间】:2012-05-03 12:28:10
【问题描述】:

我正在尝试使用 sencha touch on rails 加载资源,但出现以下错误:

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

【问题讨论】:

    标签: ruby-on-rails sencha-touch extjs


    【解决方案1】:

    如果您的 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
    

    顺便说一句:从我看到的here 来看,您可能应该将代理代码移动到MenuItem 模型中。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-27
        • 2012-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多