How can I get sencha architect to read json from rails

I have a Ruby on Rails 3 news application. This requires a headline, some content, and an image attachment (using a clip recorder). I use the RABL gem to provide a Sencha Architect project with a JSON feed .

The problem is that Sencha Architect cannot read JSON URLs. When I try to load data into the storage, I get a very useless message: "Unable to load data using the supplied configuration" and a link to open the URL in the browser (which opens just fine). Does the Sencha archive have a log somewhere that provides additional information about this error?

Here are the RABL files:

# show.rabl object @article attributes :title, :body node(:mobile_url) { |article| article.image.url(:mobile, false) } node(:tablet_url) { |article| article.image.url(:tablet, false) } node(:original_url) { |article| article.image.url(:original, false) } # index.rabl collection @articles extends "articles/show" 

RABL does not provide a default content type, so I have this in the article controller:

 before_filter :default_format_json def default_format_json if(request.headers["HTTP_ACCEPT"].nil? && params[:format].nil?) request.format = "json" end end 

This is the code created by the architect to show the configuration options that I used:

 # Stories store Ext.define('MyApp.store.Stories', { extend: 'Ext.data.Store', requires: [ 'MyApp.model.Story' ], config: { autoLoad: true, model: 'MyApp.model.Story', storeId: 'Stories', proxy: { type: 'jsonp', url: 'https://feedr.org.uk/articles.json', reader: { type: 'json', rootProperty: 'article' } } } }); # Story model Ext.define('MyApp.model.Story', { extend: 'Ext.data.Model', config: { fields: [ { name: 'title' }, { name: 'body' }, { name: 'mobile_url' }, { name: 'tablet_url' } ] } }); 

How can I get Sencha Architect to read my JSON data? Any help you can provide is greatly appreciated.

+4
source share
2 answers

Well, it turns out that there is nothing wrong with Sencha's configuration, the problem was in my rails application. I am using the RABL stone to generate a Json response. RABL must be configured to generate a JsonP response in the form of an initializer as follows:

 # config/initializers/rabl_init.rb Rabl.configure do |config| config.include_json_root = false config.include_xml_root = false config.enable_json_callbacks = true end 

An important option is enable_json_callbacks = true . This forces RABL to serve the response as JsonP, which my Sencha application can understand.

+1
source

Not sure if this applies, but when I worked with sencha, I had to use it in my store

  config: { autoLoad: true, model: 'UniversityData.model.Person', proxy:{ type:'ajax', url: 'persons.json' }, sorters: ['lastName', 'firstName'], grouper: { groupFn: function(record){ return record.get('lastName')[0]; } } } 

It seems that the only difference is

  type: 'jsonp' to my type: 'ajax' 
0
source

Source: https://habr.com/ru/post/1445063/


All Articles