0

I am trying to build a app with rails & spine that support offline browsing. I am facing problem in use of Spine.Model.Local in my one of model. Can any explain me that how we use Spine.Model.Local in our rails & spine app. Thanks

Lalit Kumar Maurya
  • 5,475
  • 2
  • 35
  • 29

2 Answers2

0

Assuming you have checked out the docs on Spine.js for localStorage use http://www.spinejs.com/docs/local what specific question do you have?

aeischeid
  • 576
  • 3
  • 12
0

First read full Spine Documentation for creating spine App.

After spending a lot of time i done it and store my rails model data into a specific spine model and use it locally for fast response.

First :: Define your spine model as below..

class App.ModelName extends Spine.Model
  @configure 'ModelName', 'columeName1', 'columeName2', ....(and other column)

  @extend Spine.Model.Local
  @extend Spine.Model.Ajax

  # other methods, variables, etc.
  # define your methods

Second :: Now sync data of specific model through your rails with ajax and put it in local storage like below...

//Request for sync model data for current login user
    Spine.Ajax.queue(function() {
        $.ajax({
            contentType : "application/json",
            dataType : "json",
            headers : {
                "X-Requested-With" : "XMLHttpRequest"
            },
            url : "/yourDesiredURL.json",
            type : "get",
            success : function(data, status, xhr) {
                for (key in data) {
                    window.localStorage[key] = JSON.stringify(data[key])
                }
                new App({
                    el : $("#app")
                });
            },
            error : function(xhr, statusText, error) {
                // Do what do you want to do
            }
        });
    }); 

Now your desired model data filled into local storage and ready to play with Spine (javascript MVC framework).

Lalit Kumar Maurya
  • 5,475
  • 2
  • 35
  • 29