Sencha Touch Rails 3.1

I am trying to load a resource using sencha touch on rails, but I get the following error:

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"):

My store code:

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 }
                }
            })
+1
source share
2 answers

If your Rails code looks something like this, then the problem is probably in the method OPTIONSthat is used - the action indexonly answers GET. Do you know why it is used here OPTIONS? I cannot find this in the Sencha Touch doc for data warehouse.

# 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

By the way: from what I see here , you should move the proxy code to the model MenuItem.

0
source

OPTION Cross-Origin Resource Sharing (CORS). . rack-cors gem, .

0

All Articles